Price history with SCD2
Extend a starter fact table with a dimension that supports accurate historical price analysis.
Concept
slowly-changing-dimensions
The primary modeling idea this problem reinforces.
Requirements
4
Business needs the model must satisfy.
You inherit a fact table for order items. The business needs a product dimension that supports price changes over time without corrupting historical revenue analysis.
This is the first step where you move from recognizing a pattern to designing the schema. Naming a Type 2 dimension is the easy part. The work is making the fact-to-dimension relationship support correct historical analysis.
- Add a dimension for products with a surrogate primary key.
- Floor: track when each product-version row becomes effective (effective-from).
- Declare an explicit foreign-key relationship from the fact table into the dimension surrogate key.
- Grade up: record when each version expires (effective-to) so the validity window is explicit.
Template
Price history starter workspace
The model users start from in the full workspace.
Entities
1
Seeded tables visible in the public preview.
Dialect
postgresql
Generated SQL target for this starter model.
This preview is read-only. Open the workspace to edit and verify; saving needs a free account.
Open workspaceTry the question first.
The discussion has other people's approaches and solutions. Give it a real attempt before you read them.