Thursday, May 19, 2011

MDX - Get quarter number from current month time member

If you are passing month time member in your MDX to slice cube and need to get quarter number for some calculation, you can try something like this. Assume a case where you are showing monthly measure value on the report but the quarterly target. In this case you will need to derive quarter number from month parameter passed in the MDX and define a calculated member for target.

Find MDX example below –

WITH 
//Find quarter number from time member
MEMBER MEASURES.[QUARTER NUMBER]
AS
Cint(Round(YTD().Count + 1) / 3)
MEMBER [Measures].[TARGET VALUE]
AS
MEASURES.[QUARTER NUMBER] * [Measures].[TARGET] / 4
SELECT
{
MEASURES.[QUARTER NUMBER]
,[Measures].[TARGET VALUE]
}
ON COLUMNS
,{StrToSet(@ParamTimeHier)}
ON ROWS
FROM
(
SELECT
StrToSet(@ParamTimeHier)
ON COLUMNS
FROM
[YOUR CUBE]
);

No comments:

Post a Comment