SSAS How-To: Create Dynamic Time Calculations To Reuse Over Any Measure
February 7, 2013 3 Comments
Rather than making individual time calculations for each measure in an SSAS cube (i.e. YTD, Prior YTD, YTD Variances, etc), one can use a more dynamic approach to time calcs applicable to all measures and save a great amount of dev time and overhead in the process.
1. Create Named Query in DSV:
UNION
SELECT 2, ‘YTD’
UNION
SELECT 3, ‘PY YTD’
UNION
SELECT 4, ‘YTD Chg’
UNION
SELECT 5, ‘YTD Chg %’
2. Create the dimension and add it to the Dimension Usage tab of the cube (no relations to the fact will exist)
3. Add the MDX script calculations:
AGGREGATE
(
PERIODSTODATE
(
[Date].[Calendar Hierarchy].[Calendar Year],
[Date].[Calendar Hierarchy].CURRENTMEMBER
)
);
AGGREGATE
(
{[Date Calculations].[Date Calculations].[Selected Date]} *
PERIODSTODATE
(
[Date].[Calendar Hierarchy].[Calendar Year],
PARALLELPERIOD
(
[Date].[Calendar Hierarchy].[Calendar Year],
1,
[Date].[Calendar Hierarchy].CURRENTMEMBER
)
)
);
IIF
(
[Date Calculations].[Date Calculations].[PY YTD] = 0,
NULL,
([Date Calculations].[Date Calculations].[YTD] – [Date Calculations].[Date Calculations].[PY YTD]) /
[Date Calculations].[Date Calculations].[PY YTD]
);
CREATESET CURRENTCUBE.[Current Year]
AS {(strtomember(“[Date].[Calendar Hierarchy].[Calendar Year].[“+ cstr(year(now()))+”]”))}, DISPLAY_FOLDER = ‘Named Sets’ ;
TAIL
(
NONEMPTY
(
[Date].[Calendar Hierarchy].[Month Name Year],
[Measures].[Fact Sales Count]
)
);
The result!
Like the post (Dynamiic Time Calculations) especially since I am confronted with the following:
8 Date dimensions, each with 3 Hierarchies (YQMD, YWD, Cycle YQCycle)
100 Measures; okay, actually 92
Until reading this I thought I was going to be creating 24 * 100 = 2,400 calculations which would mean 2,400 visible to the User Measures; UGH! I wouldn’t even wish that on my ex-wife. If they can choose which to show (via Filter) I am easily back to an elegant solution rather than a kludge.
I am trying your solution now and will let you know how it works for this situation.
Darn, darn, darn… sure hope it is the solution. If it is I will spread the word far and wide…
Kindest Regards,
Kurt J. Vesecky
Any luck?
Thanks for your response but I think I am still confused by the SCOPE statements. Unfortunately I will need some time to understand them although I can say your solution does work.
Regards,
Kurt J. Vesecky