SSRS :MDX Query to get a particular Granularity of Timeperiod (Dynamic MDX in SSRS )

Case Study : When a user want to select the Particular Granularity of time in his report  when the data is coming from SSAS Cube .

Granularity :

Q – Quaterly  ( for every 15 mins data)
H – Hourly
D – Daily
W – Weekly
M – Monthly
Y – Yearly


Solution :

Step 1
Create a Parameter Called Granularity and give the Values as shown below .

Step 2 : In Main Data Set
Create a parameterized named set  called Peroid  as shown below

 

with set Period as

CASE @Granularity      WHEN "H" THEN  {[Date].[Year -  Month -  Date].[Date].members *[Time].[Time Hierarchy].[Hour].members}

                                  WHEN  "D" THEN  {[Date].[Year -  Month -  Date].[Date].members}

                                  WHEN  "M" THEN  {[Date].[Year -  Month -  Date].[Month].MEMBERS}

                                  WHEN  "Y" THEN {[Date].[Year -  Month -  Date].[Year].members}

                                  ELSE {[Date].[Year -  Month -  Date].[Month].MEMBERS}

 

  END



Step 3 : Create a Named Member called Period 1 to use the Caption name on the Report

With MEMBER MyPeriod1 as iif([Time].[Time Hierarchy].CurrentMember is [Time].[Time Hierarchy].[All],[Date].[Year -  Month -  Date].currentmember.member_caption,[Time].[Time Hierarchy].CurrentMember.member_caption)


Step 4 : Use This Period1,Period2  members  in Chart Category Groups .

The Final MDX Query Looks Like


with set Period as

CASE @Granularity      WHEN "H" THEN  {[Date].[Year -  Month -  Date].[Date].members *[Time].[Time Hierarchy].[Hour].members}

                                  WHEN  "D" THEN  {[Date].[Year -  Month -  Date].[Date].members}

                                  WHEN  "M" THEN  {[Date].[Year -  Month -  Date].[Month].MEMBERS}

                                  WHEN  "Y" THEN {[Date].[Year -  Month -  Date].[Year].members}

                                  ELSE {[Date].[Year -  Month -  Date].[Month].MEMBERS}

 

  END

MEMBER MyPeriod1 as iif([Time].[Time Hierarchy].CurrentMember is [Time].[Time Hierarchy].[All],[Date].[Year -  Month -  Date].currentmember.member_caption,[Time].[Time Hierarchy].CurrentMember.member_caption)

MEMBER MyPeriod1 as iif([Time].[Time Hierarchy].CurrentMember is [Time].[Time Hierarchy].[All],[Date].[Year -  Month -  Date].currentmember.member_caption,[Time].[Time Hierarchy].CurrentMember.member_caption)

 

MEMBER MyPeriod2 as iif([Time].[Time Hierarchy].CurrentMember is [Time].[Time Hierarchy].[All],[Time].[Time Hierarchy].CurrentMember.member_caption,[Date].[Year -  Month -  Date].currentmember.member_caption)

 

SELECT NON EMPTY { [Measures].[CS_DC],[Measures].[AC_DC],[Measures].[CALL_ATTEMPTS], MyPeriod1,MyPeriod2} ON COLUMNS ,

 

NON EMPTY {[Network Equipment].[Network Equipment Hierarchy].[bsc].members *Period} ON ROWS

FROM ( SELECT ( STRTOSET(@MSC, CONSTRAINED) ) ON COLUMNS

FROM ( SELECT ( STRTOSET(@BSC, CONSTRAINED) ) ON COLUMNS

FROM ( SELECT ( STRTOSET(@BTS, CONSTRAINED) ) ON COLUMNS

FROM ( SELECT ( STRTOSET('[Date].[Year -  Month -  Date].[Date].&['+@SampleDate+'T00:00:00]:[Date].[Year -  Month -  Date].[Date].&['+@Movingdate+'T00:00:00]') ) ON COLUMNS

FROM [Core GSM]))))


Comments

Popular posts from this blog

SSAS : A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running. (Microsoft.AnalysisServices.AdomdClient). + Solution

SSIS Error : Unable to infer the XSD from the XML file. The XML contains multiple namespaces