0
votes

I have a problem when I write scopes statement to calculate Calendar Year-To-Date Values in cube using SSAS.

Here is my Date Dimension and its hierarchy: enter image description hereenter image description here

In measures group, I have a measure named [Sales Amount] which is the sales amount of each item in date. I want to calculate year-to-date value. Here is my scope statement but it don't work well.

   SCOPE(MEASURES.[YTD Sales]);
         --Calendar YTD
         SCOPE([DimDates].[Year-Qtr-Month-Day].MEMBERS, [DimDates].[Year].[Year].MEMBERS);
             THIS = AGGREGATE(
                     PERIODSTODATE([Date].[Year].[Year], [Date].[Year].CURRENTMEMBER), 
                     [Measures].[Sales Amount]);
         END SCOPE; 
END SCOPE;
2

2 Answers

0
votes

(I don't play with the cube scripts myself so feeling around in the dark a bit)

I think you need to not have a year member as the second argument inside the PERIODSTODATE function: it needs a member from a lower level to understand where to do the ytd calculation up to. So looking at your current script I think inside the function you should use you user hierarchy [Year-Qtr-Month-Day] rather than the attribute hierarchy [Year]?

SCOPE(MEASURES.[YTD Sales]);
         --Calendar YTD
         SCOPE([DimDates].[Year-Qtr-Month-Day].MEMBERS, [DimDates].[Year].[Year].MEMBERS);
             THIS = AGGREGATE(
                     PERIODSTODATE([DimDates].[Year-Qtr-Month-Day].[Year], [DimDates].[Year-Qtr-Month-Day].CURRENTMEMBER), 
                     [Measures].[Sales Amount]);
         END SCOPE; 
END SCOPE;

Can this be simplified via the YTD function?
Looking in MSDN I can see the following: https://msdn.microsoft.com/en-us/library/ms146039.aspx
Applying to your script it maybe gives something like the following:

SCOPE(MEASURES.[YTD Sales]);
         --Calendar YTD
         SCOPE([DimDates].[Year-Qtr-Month-Day].MEMBERS, [DimDates].[Year].[Year].MEMBERS);
             THIS = AGGREGATE(YTD(), [Measures].[Sales Amount]);
         END SCOPE; 
END SCOPE;
0
votes

Thanks whytheq for your answer and also your correction for my post :-D

I have had a look at your tutorial about YTD() function, it's not really the think I want but it give some idea for my work. Finally, my script works well. I share my code for the another people in further (Thanks if you can correct my english for me :p )

CALCULATE;

SCOPE([Measures].[Sales Amount YTD]);
   --Calendar YTD
   SCOPE([DimDates].[Date].MEMBERS, [DimDates].[Year].[Year].MEMBERS);
     THIS = AGGREGATE(
               PERIODSTODATE([DimDates].[Year-Qtr-Month-Day].[Year], [DimDates].[Year-Qtr-Month-Day].CURRENTMEMBER), 
[Measures].[Sales Amount]);
   END SCOPE;
End scope;