Start a new topic
Answered

How do I handle slowly changing dimension tables in 1010data?

I have some slowly changing dimension tables for attributes with start and end effective dates that I want to combine in an analysis. In a traditional SQL database, I would use an inequality join. What should I be using in 1010data to perform this link?


Best Answer

1010data has a mechanism specifically to join slowly changing dimensions to fact tables, called as-of links. Let's take an example with a Sales and a slowly moving Product table, below.


Sales Table Sales Table


Product Dimensions -- Slowly Changing enter image description here


In this case we want to bring in the cost data, which is updated over time into Sales. We always want the latest cost data added. Matching these within 1010data means an as-of link. The Macro Code for this is here:

<base table="sales_table"/> <link table2="product_dims_slowly_moving"     col="product, date"     col2="product, update_date"     type="asof"/> 


The result of this is here: enter image description here

Key takeaways from this are...

  • The last column in Col and Col2 are the slowly moving dimension match column (as-of). In this case product is exactly matched and then the last column brings in the latest value. 
  • In row 2, you see that if the only values for a given product happen "after" the asof match date, you'll see there is no match
  • Very important --> the slowly changing dimension table has to be sorted! Notice that this table is sorted by product and by update_date. This is required for asof link to work properly

More information and a detailed guide can be found here: https://www2.1010data.com/documentationcenter/prime/1010dataUsersGuide/index_frames.html?q=Linking/AsOfLinks.html

Answer

1010data has a mechanism specifically to join slowly changing dimensions to fact tables, called as-of links. Let's take an example with a Sales and a slowly moving Product table, below.


Sales Table Sales Table


Product Dimensions -- Slowly Changing enter image description here


In this case we want to bring in the cost data, which is updated over time into Sales. We always want the latest cost data added. Matching these within 1010data means an as-of link. The Macro Code for this is here:

<base table="sales_table"/> <link table2="product_dims_slowly_moving"     col="product, date"     col2="product, update_date"     type="asof"/> 


The result of this is here: enter image description here

Key takeaways from this are...

  • The last column in Col and Col2 are the slowly moving dimension match column (as-of). In this case product is exactly matched and then the last column brings in the latest value. 
  • In row 2, you see that if the only values for a given product happen "after" the asof match date, you'll see there is no match
  • Very important --> the slowly changing dimension table has to be sorted! Notice that this table is sorted by product and by update_date. This is required for asof link to work properly

More information and a detailed guide can be found here: https://www2.1010data.com/documentationcenter/prime/1010dataUsersGuide/index_frames.html?q=Linking/AsOfLinks.html

Login to post a comment