Forum Discussion
How to dynamically update MTD/QTD/YTD for SSAS MD
Ok parry2k
Keep your MTD,QTD,YTD calculation based on your [Dates].[Calendar] hierarchy using currentMember.
Your card show "blank" because your filter context doesn't specify any values on your [Dates].[Calendar] hierarchy.
To do that dynamically :
1. create a member and a dynamic set to identify your today value
CREATE MEMBER CURRENTCUBE.[Measures].[Now]
AS Now(),
FORMAT_STRING = "YYYYMMDD",
VISIBLE = 0 , DISPLAY_FOLDER = 'Calculation Members';
CREATE DYNAMIC SET CURRENTCUBE.[Today]
AS StrToMember("[Date].[Calendar YQMD].[Date].&[" + CSTR(YEAR([Measures].[Now]) * 10000 + Month([Measures].[Now]) * 100 + Day([Measures].[Now])) + "]"), DISPLAY_FOLDER = 'Named Sets';2. Scope your MTD, QTD,YTD and force your [Dates].[Calendar] hierarchy when level ordinal is not as the good depth :
SCOPE ([Measures].[Sales Amount YTD]);
THIS =
CASE
WHEN [Date].[Calendar YQMD].level.ordinal = 0 THEN
SUM([Today],[Measures].[Sales Amount YTD])
ELSE
[Measures].[Sales Amount YTD]
END;
END SCOPE;
SCOPE ([Measures].[Sales Amount MTD]);
THIS =
CASE
WHEN [Date].[Calendar YQMD].level.ordinal < 3 THEN
SUM([Today],[Measures].[Sales Amount MTD])
ELSE
[Measures].[Sales Amount MTD]
END;
END SCOPE;
You could also alter your cube and set a default value to your date dimension.
Thanks for the solution but I see one challenge with this. If user put a date slicer on the report, and select a date, it will always show MTD/YTD for today.
May be I need to tweak the solution to make it work.
Thanks,
P
- fbrossard10 years ago
Kudo Commander
Not at all, it will display the MTD, YTD for the selected date.
When a date is not selected, it calculate automatically on today else on date/period you select.