http://www.sqlservercentral.com/blogs/dknight/2009/12/03/mdx-utility-belt-of-calculations-part-3/

Printed 2014/07/25 03:33AM

MDX Utility Belt of Calculations Part 3

2009/12/03

This is part three in a series of blog posts that will help you build an arsenal of MDX calculations that you can have ready at the drop of a dime.  The first two posts of this blog series use the ParrallelPeriod and PrevMember functions to return data at different levels.

All of these blog posts are formatted to give you the business problem, a general solution and then the calculation needed to finish the job.  The problem this time will use part of the solution we used from the second blog post.

Problem

You need to show the difference in sales of a date and that date's previous member.  (Ex.  Show the sales difference between June and July.  Could likely be a negative number if there are fewer sales in July.)

Solution

You can return the sales for the CurrentMember and subtract it from the value of previous member using PrevMember.

Calculations

The sales for a year minus the sales of the previous year

([Date].[Year].CurrentMember,[Measures].[Sales Amount])-
([Date].[Year].PrevMember,[Measures].[Sales Amount])

---------------------------------------------------------------

The sales for a quarter minus the sales of the previous quarter

([Date].[Quarter].CurrentMember,[Measures].[Sales Amount])-
([Date].[Quarter].PrevMember,[Measures].[Sales Amount])

---------------------------------------------------------------

The sales for a month minus the sales of the previous month

([Date].[Month].CurrentMember,[Measures].[Sales Amount])-
([Date].[Month].PrevMember,[Measures].[Sales Amount])


Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.