Archive

Posts Tagged ‘ParallelPeriod’

MDX – Variance using PARALLELPERIOD

December 19, 2011 Leave a comment

This weekend I am planning on how to convert few static reports to dynamic reports to give more functionality to end-user.
The requirement is to have the variations of all the years with respect to previous years and the existing functionality is to accommodate only one year at time so the user needs to select a particular year and the report will render to get previous year and the variations.
Here I end up with few lines of codes with one function PARALLELPERIOD() to get the dynamic variations of all the periods as

WITH MEMBER [measures].[Previous Year Internet Sales Amount] 
AS
( 
[Measures].[Internet Sales Amount], 
PARALLELPERIOD
([Date].[Calendar Year].[Calendar Year], 1, [Date].[Calendar Year].CurrentMember) 
),FORMAT_STRING = "Currency"

MEMBER [measures].[Varience]  AS
(
[Measures].[Internet Sales Amount] - [measures].[Previous Year Internet Sales Amount]
)
SELECT {[measures].[Previous Year Internet Sales Amount],[Measures].[Internet Sales Amount]
, [measures].[Varience]} ON COLUMNS
, [Date].[Calendar Year].children ON ROWS
FROM [Adventure Works]


 
Updating this post with one more interesting functionality PercentVarirance

WITH MEMBER [measures].[Previous Year Internet Sales Amount] 
AS
( 
[Measures].[Internet Sales Amount], 
PARALLELPERIOD
([Date].[Calendar Year].[Calendar Year], 1, [Date].[Calendar Year].CurrentMember) 
),FORMAT_STRING = "Currency"

MEMBER [measures].[Varience]  AS
(
[Measures].[Internet Sales Amount] - [measures].[Previous Year Internet Sales Amount]
)
MEMBER [Measures].[PercentageVarience] AS
(
CASE WHEN [measures].[Previous Year Internet Sales Amount] IS NULL OR ISEMPTY([measures].[Previous Year Internet Sales Amount]) THEN 1
     WHEN [measures].[Internet Sales Amount] IS NULL THEN -100 
ELSE [measures].[Varience] 
 /
[measures].[Previous Year Internet Sales Amount] 
END )
,FORMAT_STRING = "Percent"

SELECT {[measures].[Previous Year Internet Sales Amount]
       ,[Measures].[Internet Sales Amount]
       ,[measures].[Varience],[Measures].[PercentageVarience]} ON COLUMNS
       ,[Date].[Calendar Year].children ON ROWS
FROM [Adventure Works]


 
1. Used PARALLELPERIOD() to get the previous year value of the currentmember of the year
2. Used the standard variance calculations
3. I am also planning to try Var() function for an alternative options for this scenario

Categories: MDX Tags: