Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

Lag function

$
0
0

Hello I want to calculate the sum of last 30 days from the current day selected. I have the following code:

CREATE MEMBER CURRENTCUBE.[MEASURES].[Points - Last 30 days]
as
Sum
    (
      {
          [Time ds].[Date].CurrentMember.Lag(30)
        : 
          [Time ds].[Date].CurrentMember
      }
     ,[MEASURES].[Points]),
VISIBLE =1;

However , I do not want to count Sundays in these. 

So I have filter which tells you whether its a Sunday or not. 

I modified the code in the following way:

CREATE MEMBER CURRENTCUBE.[MEASURES].[Points - Last 30 days]
as
Sum
    (
      {
          [Time ds].[Date].CurrentMember.Lag(30)
        : 
          [Time ds].[Date].CurrentMember
      }
     ,Sum([Time ds].[Sunday].&[No],[MEASURES].[Points])),
VISIBLE =1;

However, it does not work. I am getting random numbers

([MEASURES].[Points] is a long calculated measure which somewhere in its root calculation has average of last 7 days , I dont know if that would matter)

Please let me know if there is any other better way of ignoring a particular day of the week ( Sunday).

It is ok if it sum 26 days instead of 30 days ( as we have 4 sundays in 30 days)

Can I use a Hierarchy? Please let me know the syntax. I tried:

CREATE MEMBER CURRENTCUBE.[MEASURES].[Points - Last 30 days]
as
Sum
    (
      {
          [Time ds].[Hierarchy].[Sunday].&[No].CurrentMember.Lag(30)
        : 
         [Time ds].[Hierarchy].[Sunday].&[No].CurrentMember
      }
     ,[MEASURES].[Points]),
VISIBLE =1;

ERROR :( :(

Thanks.





Viewing all articles
Browse latest Browse all 2472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>