Tuesday, January 8, 2013

How to flatten (de-normalize, spread) fact table with time duration in data warehousing design

Context
Based on Kimball methodology, there are three different kinds of fact tables: transactional, periodic snapshot and accumulating snapshot. The case in this document is a special case of transactional fact.  For the sake of explanation, assume that there are action fact table with start date and duration. It is requested to have action days and then compare with objective days. All related metrics are on a monthly basis, or year to date basis. The requirement becomes challenge when an action is cross month end. Therefore flatten fact table is needed in staging load.

Sample

Given action fact table for month August
Dimension columnsAction dateAction Duration
xyzAugust 1, 201218 days
xyzAugust 30, 20125 days



Give objective table for month August

Dimension columnsObjective monthObjective Duration
xyzAugust20 days


Then the difference between action days and objective is 3 days, which actually is wrong.

Dimension columnsMonthAction DurationObjective DurationDifference
xyzAugust23 days20 days23-20 = 3 days


Solution

The solution is to spread all actions on daily basis based on business day, see below
Dimension columnsAction dateAction Duration
xyzAugust 1, 20121 day
xyz…………..1 day
xyzAugust 29, 20121 day
xyzAugust 30, 20121 day
xyzAugust 31, 20121 day
xyzSeptember 4, 20121 day
xyzSeptember 5 , 20121 day
xyzSeptember 6, 20121 day


Now the difference between action days and objective is 0 days, which actually is right.
Dimension columnsMonthAction DurationObjective DurationDifference
xyzAugust20 days20 days20-20 = 0 days

No comments:

Post a Comment