Question

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
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top