Archive

Archive for November, 2012

MDX #21 – Days in a month

November 22, 2012 Leave a comment

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

Categories: MDX Challenges Tags: ,

MDX #20 – Last Data Date

November 22, 2012 1 comment

Need to check the last time when our ETL processes ran successfully

Data warehouse developers routinely query the last data date (the last date when we have fact data) to check the last time when our ETL processes ran successfully.

It’s not hard to do it in TSQL. It just requirements a bit of typing. In this example, I am showing the last data date in its readable format and the Sales Amount on that day.

clip_image001

A lot easier to do this in MDX

It’s actually a lot easier to do this in MDX. With the help of the TAIL() function and the NONEMPTY() function, the last data date is easy to query without any sub-queries or calculations.

clip_image002

Always verify

To make sure we got it right, run this simple query to verify.

clip_image003

Note: There is no need to order by the Date dimension. It’s already ordered in the SSAS.

Categories: MDX Challenges Tags: ,

SSIS C Sharp #115 – C# Script to detect delta

November 3, 2012 1 comment

A reader asked me to share a C Sharp script I used in this post, SSIS #114 – How many ways can you do INSERT-UPDATE?.

This code snippet tried to determine if the original value of MyFirstColumn is different or not compared to the incoming data in the pipeline. It is used in the last UPDATE-DELTA design.

image

Notes:

The Script Component needs some configuration. Without the proper configuration, the above code will not work.

Categories: SSIS Best Practices Tags: ,
%d bloggers like this: