Is there a better way to calculate the moving average in an MDX in iccube?

StackOverflow https://stackoverflow.com/questions/20075636

  •  31-07-2022
  •  | 
  •  

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
Était-ce utile?

La 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top