3

I'm using the following calculated member to calculate the moving average for my visits for the last 30 days period; is there a shorter way to do this?

WITH 
  MEMBER [Measures].[Visits Moving Avg] AS 
      AVG(
        [TIME].[Time].Prevmember : [TIME].[Time].Prevmember.Prevmember.Prevmember....
        , [Measures].[VISITS] 
      ), SOLVE_ORDER = 0
JAL
  • 41,701
  • 23
  • 172
  • 300
Aron
  • 73
  • 6

1 Answers1

3

Instead of using the serie of prevMember.prevMember... calls you can use the Lag MDX function function as following :

WITH 
  MEMBER [Measures].[Visits Moving Avg] AS 
      AVG(
        [TIME].[Time].prevMember : [TIME].[Time].prevMember.lag(30)
        , [Measures].[VISITS] 
      ), SOLVE_ORDER = 0

By the way, it looks like currentMember is missing in your query; you are currently computing the moving average for the defaultMember of the [Time] dimension. The query using the currentMember of the time dimension is as following :

WITH 
  MEMBER [Measures].[Visits Moving Avg] AS 
      AVG(
        [TIME].[Time].currentMemBer.prevMember
            : [TIME].[Time].currentMemBer.prevMember.lag(30)
        , [Measures].[VISITS] 
      ), SOLVE_ORDER = 0
ic3
  • 7,917
  • 14
  • 67
  • 115
Marc Polizzi
  • 9,275
  • 3
  • 36
  • 61