Home > MDX Challenges > MDX #21 – Days in a month

MDX #21 – Days in a month

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

About these ads
Categories: MDX Challenges 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

Follow

Get every new post delivered to your Inbox.

Join 169 other followers

%d bloggers like this: