Blog Post

MDX Time Calculation Shortcuts

,

There are lots of ways to calculate time comparisons in MDX, but there are some great shortcuts. The functions WTD, MTD, QTD and YTD allow you to work with Week, Month, Quarter, and Year, respectively. In ways that would require more coding than normal using a different function or method.

Let’s take a look at how these work.

The "TD" functions as we’ll call them work the same way: They return a set of members from the date dimension starting with the first day of the period in question (Week, Month, etc..), up to the specified member.

These functions are great for simple cubes when you need to returns a Set of members from the first day of the week up through the specified member

For Example this will return a set of members from Feb 14th, 2010 to Feb 19th, 2010.

WTD([date].[calendar].[date].[February 19, 2010] )

This will return all members from the February up to Feb 19th, 2010

MTD([date].[calendar].[date].[February 19, 2010] )

This will return all members from the First Quarter up to Feb 19th, 2010

QTD([date].[calendar].[date].[February 19, 2010] )

This will return all members from 2010 up to Feb 19th, 2010

YTD([date].[calendar].[date].[February 19, 2010] )

You can also run these with no parameters if you have only one hierarchy and it will assume the CurrentMember from your date dimension. The syntax for that is WTD(), MTD(), QTD(), or YTD(). It is best practice to specify the member, that way growth will not impact your calculation logic.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating