Monday, December 1, 2008

Slowly Changing Dimension Type 2 with Effective From and Effective To Dates

I have a source table with some records to demonstrate SCD Type2like below:

I have ModifiedDate in the source table, which i have to make use of to capture EffectiveFromDate and EffectiveToDate in the destination dimension table. I have invoked the SCD Transformation, and have set AssetTypeName to be Historical Change attribute with AssetId as BusinessKey. So for any change in the source for AssetTypeName, i will have to expire the old record and insert a dimension record. I have used start dates and end dates to identify current records and System:StartTime as the variable to set date values, as below.


In the SCD wizard generated mapping, i have changed the derived column transformation to represent the modified date. In the derived column for the new row path changed the derived column transformation to include EffectiveFrom as new column with values as "modifieddate" of the source table. In the path to expire records changed the derived column transformation to include EffectiveTo as new column with value "modifieddate" like below.



Running the package for the first time has populated the dimension table like below.



Now in the source table, the record with AssetId = 1 is modified on 11/14/2008 when the AssetTypeName field (historical field of SCD) is updated as "FullMask" inplace of "Mask". The source table will look like below


Now executing the SCD package will populate the dimension like below.

Now there is a a new dimension record with a effectivefrom date and the old dimension record has been expired with a effectiveto date.
To get the correct surrogate key for this type of dimension to load the fact table, read this
http://robinbi.blogspot.com/2008/12/lookup-surrogate-key-from-dimension.html