Data Warehouse Design Techniques – Slowly Changing Dimensions

In my last blog post, I demonstrated the importance of conformed dimensions to the flexibility and scalability of the warehouse. This week we will discuss the importance of capturing the dimensional change in slowly changing dimensions.

Slowly Changing Dimensions

Slowly Changing Dimensions (SCD) are the most commonly used advanced dimensional technique used in dimensional data warehouses. Slowly changing dimensions are used when you wish to capture the changing data within the dimension over time. There are three methodologies for slowly changing dimensions.

Type 1 – For this type of slowly changing dimension you simply overwrite the existing data values with new data values. This makes the updating of the dimension easy and limits the growth of the dimension table to only new records. The drawback of this is you lose the historical value of the data because the dimension will always contain the current values for each attribute. For instance, you have a store dimension which has an attribute for a geographic region. If there is a redesign in the regional boundaries some stores may move from one region to another. Because the record is simply updated a store which may have been reporting results in the Northeast district will now report their results to the Mid-Atlantic region. But, as a result of the update, now all of the history for that store before the move is essentially removed from the Northeast and moved to the Mid-Atlantic district. This change will skew the historical reports and the reports run before the update will no longer match the reports run after the update for the same timeframe.

Type 2 – This is the most commonly used type of slowly changing dimension. For this type of slowly changing dimension, add a new record encompassing the change and mark the old record as inactive. This allows the fact table to continue to use the old version of the data for historical reporting purposes leaving the changed data in the new record to only impact the fact data from that point forward. Several columns should be added to the dimension table (active record start/end dates and a current active record flag) to provide historical change management and ensure optimal use of the active record. Using the same example from the Type 1 dimension above, the change in the district will cause the updating of the current active dimension record’s active record end data and active record flag denoting this record is no longer actively in use. This will also spawn the creation of a new active record with a new dimension key. This new dimension key will be used in the generation of the fact table moving forward. This allows the fact table to still use the data stored under the old dimension key for historical reporting. This will ensure that the data remains the same and a historical report for the same timeframe run before the update was made will continue to display the exact same data as before the change was made.

Type 3 – This is a seldom used type of slowly changing dimension. In this type of slowly changing dimension you add a second column to store the most recent past value of the column(s) you wish to be able to report on. When the data is updated the existing value is “moved” to the column defined to store the previous past value and the new value is placed into the reportable column. This allows you the ability to look back at what the value of the data was previously. This can be a challenge when loading/updating the data. The amount of work to design and maintain this solution far exceed the benefit the “fallback snapshot” provides.

Type 6 – A Type 6 SCD is a very rarely used SCD. In this instance, you combine SCD Type 1, SCD Type 2 and SCD Type 3 (1 + 2 + 3 = 6). To create a Type 6 SCD you would start with a Type 2, add columns for the records you wish to capture the current value as well as the historical value. This allows one to filter or group on the Type 2 value in effect when the measure occurred or the current attribute value.

Conclusion

As you can see there are many ways to capture the changes in dimensions for current and historical reporting purposes. Because of the flexibility, I recommend that you start all design solutions using SCD Type 2 as your default solution. Keep in mind that not all attributes need to be a captured as a Type 2 SCD. I often combine Type 1 and Type 2 SCDs based on the project requirements.

BigBear.ai Privacy Policy