SSAS Named SETS: How to calculate Reference Value Based on same weekday data of previous week .

Case :In Most of the businesses we will always compare the Measure value with the Same datetime Measure value of the Previous weekday .For Example :  If we have Measure called NumberOFCalls  and we have value at 10 AM of Wednesday  ie 19th Feb 2014 Then we need to compare this measure value with same time of previous week that is  10 am of 12th Feb 2014.
The Business will compare reference value , If the difference between Current and Refernce value is more than 20% they will take some action.
Solution : when we want to  calculate the reference value based on same weekday data of previous week  in SSAS Cube  we need to Create a Named Sets for Each Weekday.
The First and very important thing is dimensional Model . You need to have the fallowing attributes in you date dimension
[The Day name] à  Like Monday , Tuesday etc..
[Is Week End] à If business wants check the reference based on Weekends/WeeKDays
[Is  Holiday] à If business wants check the reference based on Holidays
Simple Example : If we want to create Named sets of Mondays which are not in Holiday list .
CREATE SET CURRENTCUBE.[Mondays]
 AS ORDER(EXCEPT(EXISTS([Date].[Date].CHILDREN,[Date].[The Day Name].&[Monday] ),EXISTS([Date].[Date].CHILDREN, [Date].[Is Holiday].&[Y])),[Date].[Date].MEMBERVALUE, ASC);     

Similarly we can create for all weekdays.
We can also Create Named sets for Working Dates and Non working Dates
CREATE SET CURRENTCUBE.[Working Dates]
 AS EXCEPT(EXISTS([Date].[Date].CHILDREN, [Date].[Is Weekend].&[N]),EXISTS([Date].[Date].CHILDREN, [Date].[Is Holiday].&[Y]));     

CREATE SET CURRENTCUBE.[Non Working Dates]
 AS ORDER(UNION(EXISTS([Date].[Date].CHILDREN, [Date].[Is Weekend].&[Y]),EXISTS([Date].[Date].CHILDREN, [Date].[Is Holiday].&[Y])),[Date].[Date].MEMBERVALUE, ASC);     


How to Calculate  Reference value  of the Number of Calls Measure

SCOPE([Measures].[ NumberOfCalls Ref],[Mondays]);       
THIS = IIF ([Measures].[NumberOfCalls] > 0,([Measures].[NumberOfCalls],[Mondays].ITEM(RANK([Date].[Date],[Mondays])-2)),  NULL);
END SCOPE;       

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