Home > MDX > MDX – Variance using PARALLELPERIOD

MDX – Variance using PARALLELPERIOD

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

Advertisements
Categories: MDX Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: