milestone 11/12 Protect fact grain when joining versions
Join historical versions without multiplying fact rows.
CRM + ERP Integration · Follow extraction reconciliation, authoritative integration, date quarantine, quality gates, stable keys, replay-safe loads, and atomic promotion. Finish with a customer-grain capstone and field-level lineage.
approach
The fact grain is one sales line. Joining a customer to every historical version multiplies rows and totals. Choose the current version for current-state reporting or effective version at event time for historical reporting. Validate row counts as well as measures; DISTINCT does not repair a wrong join.
SELECT h.country,SUM(f.sales) AS total_sales FROM fact_sales f JOIN dim_customer c ON c.customer_key=f.customer_key JOIN customer_history h ON h.customer_id=c.customer_id AND h.valid_to IS NULL GROUP BY h.country;
data for this milestone
customer_history5 columns · 3 rows
| version_keyinteger · key | customer_idtext | countrytext | valid_fromtext | valid_totext |
|---|---|---|---|---|
| 101 | C001 | United States | 2024-01-01 | 2025-02-01 |
| 102 | C001 | Canada | 2025-02-01 | NULL |
| 103 | C002 | United Kingdom | 2024-01-01 | NULL |
all 3 rows
dim_customer4 columns · 5 rows
| customer_keyinteger · key | customer_idtext | nametext | countrytext |
|---|---|---|---|
| 1 | C001 | Alice Nguyen | United States |
| 2 | C002 | Ben | United Kingdom |
| 3 | C003 | Cara | United Kingdom |
| 4 | C004 | Dev | India |
| 5 | C005 | Elena | Canada |
all 5 rows