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!