1
votes

I am trying to compute a moving average using MDX in SSAS 2014,but all results come out (null).

Reading multiple web references and blog posts makes me think that this should work, giving a 3-month moving average:

With
  MEMBER [Measures].[MA3] AS 
    Avg(
         [Date].[Calendar Years].[Month].CurrentMember.Lag(2) 
          : [Date].[Calendar Years].[Month],
         [Measures].[Project Views]
       )

SELECT  { [Measures].[Project Views], [Measures].[MA3] } ON 0,
          [Date].[Calendar Years].[Month]  ON 1
FROM [ProjectAccesses] 

However, (null) appears in each column.

I'd expect the count of members to be 3 in every case using:

  MEMBER  [Measures].[C3] AS 
    Count(
          [Date].[Calendar Years].[Month].CurrentMember.Lag(2) 
             : [Date].[Calendar Years].[Month],
          INCLUDEEMPTY
         )

but again, no syntax error is detected but all values are (null), leading me to believe that maybe the month-range sets are empty.

I've been around and around this for hours now and have run out of things to try.

Can anyone suggest what might be going wrong please; I'm a newcomer to MDX so it's possible that my query is wrongly structured or there is some error in my cube configuration that I have not been able to find.

Thanks

3

3 Answers

1
votes

I believe you need to change

": [Date].[Calendar Years].[Month],"

To

": [Date].[Calendar Years].currentmember,"

[Date].[Calendar Years].[Month] -> should give the level, not the current member which is what you want

0
votes

I'm surprised that you cannot use the Calendar Years hierarchy throughout. I've added a couple of extra diagnostic measures so you can see what the currentmember function is returning:

WITH
  MEMBER [Measures].[MA3] AS 
      AVG(
           [Date].[Calendar Years].CurrentMember.Lag(2) 
             : [Date].[Calendar Years].CurrentMember,
           [Measures].[Project Views]
         )
  MEMBER  [Measures].[C3] AS 
    COUNT(
           [Date].[Calendar Years].CurrentMember.Lag(2) 
             : [Date].[Calendar Years].CurrentMember,
           INCLUDEEMPTY
         )
  MEMBER  [Measures].[Diagn1] AS  
    [Date].[Calendar Years].CurrentMember.member_caption
  MEMBER  [Measures].[Diagn2] AS  
    [Date].[Calendar Years].CurrentMember.Lag(2).member_caption
SELECT  
    { 
      [Measures].[Project Views]
    , [Measures].[MA3] 
    , [Measures].[C3] 
    , [Measures].[Diagn1]
    , [Measures].[Diagn2]
    } ON 0,
    [Date].[Calendar Years].[Month].MEMBERS  ON 1
FROM [ProjectAccesses];
0
votes

I found the solution. I had assumed that i would need to form my set based on a member within my [Calendar Years] hierarchy. However the following, without the hierarchy, works fine (although I can't explain why the original version did not).

With
  MEMBER [Measures].[MA3] AS 
      Avg(
           [Date].[Month].CurrentMember.Lag(2) 
             : [Date].[Month].CurrentMember,
           [Measures].[Project Views]
         )
  MEMBER  [Measures].[C3] AS 
    Count(
           [Date].[Month].CurrentMember.Lag(2) 
             : [Date].[Month].CurrentMember,
           INCLUDEEMPTY
         )

SELECT  { [Measures].[Project Views], [Measures].[MA3] , [Measures].[C3] } ON 0,
          [Date].[Calendar Years].[Month]  ON 1
FROM [ProjectAccesses]