Reports must show the address at the time of the order
Customers move. The sales report must show each order with the customer's region at the time of the order, while the customer page shows the current address. How do you model the customer dimension, and how do facts join to it?
Think it through or sketch an answer first, then open the hint or the solution.
Show a hint
Keep a history of versions with validity dates.
Show the solution
Use a slowly changing dimension Type 2: each change adds a new row with its own surrogate key, valid_from, valid_to and an is_current flag. When loading facts, look up the version valid at the order date and store that surrogate key in the fact, so reports join on the key without date logic. The current address is the row with is_current = true.
Common mistakes
- Overwriting the address (Type 1), which rewrites history in every past report.
- Joining facts to the dimension on the natural key at query time, which returns all versions and multiplies rows.
How did you do? Your answer is saved in this browser and comes back for revision later.
Learn more
- Slowly Changing DimensionsData Warehouse
- Slowly Changing Dimensions: Types 1, 2 and 3Data Warehousing Deep Dive
- SCD Type 2: Two Ways on DatabricksDatabricks Advanced