I have an MDX report containing 7 parameters. The first 5 parameters are cascaded. For example Company > BusinessUnit > ReportingUnit > SubUnit > Project.
I have a requirement to set a target level based on the combination of the parameter values selected. For example, when the Company parameter value gets selected and the BusinesUnit = All and ReportingUnit = All and SubUnit = All and Project = All, set the target level to the Company parameter value. When the Company parameter value gets selected and the BusinesUnit <> All and ReportingUnit = All and SubUnit = All and Project = All, set the target level to the BusinessUnit parameter value. When the Company parameter value gets selected and the BusinesUnit <> All and ReportingUnit <> All and SubUnit = All and Project = All, set the target level to the ReportingUnit parameter value and so on. To achieve this, I have used CASE function in MDX.
The reason it has to be done this way is that the target value is not rolled up i.e. it is set at a specific level within the organisation chart.
My Query Parameters set up on SSRS is below:
My MDX query using CASE function is below:
WITH
MEMBER [Measures].[AllClassValue] AS
CASE
WHEN STRTOMEMBER(@Company).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION = “All”
THEN “[All Class Values].[Class Value].&[” + STRTOMEMBER(@Company).Item(0).MEMBER_CAPTION + “]”
WHEN STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION = “All”
THEN “[All Class Values].[Class Value].&[” + STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION + “]”
WHEN STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION = “All”
AND STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION = “All”
THEN “[All Class Values].[Class Value].&[” + STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION + “]”
WHEN STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION = “All”
THEN “[All Class Values].[Class Value].&[” + STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION + “]”
WHEN STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@ReportingUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@SubUnit).Item(0).MEMBER_CAPTION <> “All”
AND STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION <> “All”
THEN “[All Class Values].[Class Value].&[” + STRTOMEMBER(@Project).Item(0).MEMBER_CAPTION + “]”
END
SET [TargetLevel] AS STRTOMEMBER( [Measures].[AllClassValue] )
SELECT { [Measures].[Non Empty Injury Count]
, [Measures].[Last 12 Months Injury Frequency Rate]
, [Measures].[Consolidated Injury Count]
, [Measures].[Last 12 Months Consolidated Injury Frequency Rate]
, [Measures].[Fiscal Current YTD Target Value]
} ON COLUMNS
, LastPeriods(13, STRTOMEMBER(@DateMonth, CONSTRAINED) )
* [Injury Types].[Injury Type Description].&[Medical Treatment Injury]
* [Date].[Fiscal].[Month]
* [TargetLevel]
ON ROWS
FROM ( SELECT ( STRTOMEMBER(@Company, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(@BusinessUnit, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(@ReportingUnit, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(@SubUnit, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(@Project, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT [Not Cancelled Event Status] ON COLUMNS
FROM [Cube]) )))) )
The STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION returns the name of the dimension member. For example if the member value is [Class Values].[Level 2].&[Cube Consulting]&[WA], the name returned will be WA.
The “[All Class Values].[Class Value].&[” + STRTOMEMBER(@BusinessUnit).Item(0).MEMBER_CAPTION + “]” is used to convert it to a differenct dimension hiearchy, in this example, [All Class Values].[Class Value].&[WA].
In summary,
from [Class Values].[Level 2].&[Cube Consulting]&[WA] to [All Class Values].[Class Value].&[WA]
Read Full Post »