http://www.sqlservercentral.com/blogs/sherry-lis-bi-corner/2012/11/22/mdx-21-days-in-a-month/

Printed 2014/09/20 12:52AM

MDX #21 – Days in a month

By Sherry Li's BI Corner, 2012/11/22

ParallelPeriod() function is very useful when we need to present data side-by-side for two parallel periods

ParallelPeriod() function is often used when we need to present data side-by-side for two parallel periods, such as in the example below where daily data needs to be presented side-by-side for each day in October and November.

clip_image001

ParallelPeriod() is unaware which month is longer

If you have used the ParallelPeriod() function for this purpose you will surely appreciate its power. You will also experience some serious frustration too. Because ParallelPeriod() is unaware which month is longer, and it’s extremely frustrating to try to line up the days for the days when there is no data. Ideally, the query needs to be dynamic and be aware which month is longer.

clip_image002

Query to determine how many days in each month

So the first thing I’ll need to do is to query the cube to determine how many days in each month (days that have data).

This query is very similar to the query in MDX #20 – Last Data Date, with the Existing key word.

clip_image003

Without the Existing keyword, it will actually give me the number of days in the entire Date dimension. The Existing keyword forces the calculated member to be in the context of the query, which is for the month of July 2004 only.

Since I do not care each day in the month, the COUNT() function allows me to just see the number of days in the month.

clip_image004

If you need to query both months of July 2004 and August 2004, wrap both members up in { } (so they will be a set), and place it in the WHERE clause.

clip_image006



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