Slowly changing dimensions
Decide which history matters
A slowly changing dimension (SCD) describes attributes whose values can change over time. Type 1 overwrites a value, so earlier facts may be grouped under the new attribute after refresh. Type 2 retains multiple versions and associates each fact with the version that was valid when the event occurred. Choose by business attribute: a typo correction may be Type 1; customer segment at order time may require Type 2. The business must define effective time, correction policy and treatment of late facts. No production history is modified in this lab. Use the order date, not the arrival date or ship date, for customer segment attribution. The separate history file represents prepared warehouse data, not a Power BI refresh history engine.
Example 1: compare current and historical segment revenue
U1 is Standard until 2026-02-01 and Premium from that date. U2 stays Standard. With a Type 1 dimension keyed by CustomerID, U1's 200 USD appears under Premium (including January 130 USD) and U2's 50 USD under Standard. With Type 2, customer-history.csv assigns U1 version 101 to January and version 102 to February. U2 uses version 201. Facts L1–L3 use 101, L4 uses 102, L5 uses 201. Historical totals are Standard 180 USD and Premium 70 USD. Both groupings total 250 USD, but answer different questions. The business key CustomerID repeats in the Type 2 dimension; CustomerVersionKey is unique. In the semantic model, relate DimCustomerHistory[CustomerVersionKey] to SalesHistory[CustomerVersionKey], active one-to-many. For the historical report, prepare that fact key before loading and group by the version's Segment. A normal equality relationship on CustomerID alone cannot do the effective-date lookup.
Example 2: assign an effective version
Use half-open validity intervals: ValidFrom ≤ OrderDate < ValidToExclusive. The exact boundary 2026-02-01 selects version 102, not 101. This conceptual lookup is implementable in warehouse ETL; here is a read-only SQLite query for the supplied text dates (ISO YYYY-MM-DD):
SELECT s.LineID, h.CustomerVersionKeyFROM sales s JOIN customer_history h ON s.CustomerID = h.CustomerID AND s.OrderDate >= h.ValidFrom AND s.OrderDate < h.ValidToExclusiveORDER BY s.LineID;The SQL fixture uses a far-future exclusive endpoint 9999-12-31; no event reaches it. Native Power BI date-range joining is not implied. Before accepting the inner-join result, count matches with a left join and reject zero or multiple matches. For example, a hypothetical late-arriving U1 sale dated January 31 and delivered February 5 still selects 101. A gap or overlap in validity is a quality failure: do not select an arbitrary row. Historical correction requires a controlled re-key/reconciliation policy, not indiscriminate refresh. The supplied SQLite verifier tests these specific cases; no data warehouse or native Power BI is needed.
Operational constraints and review
Version intervals must not overlap within one CustomerID, must have start before end, and must cover the accepted event dates. There should be one current version per active customer by the chosen sentinel policy. Do not derive prior segment history from the latest source snapshot if the source never retained the changes. Preserve historical changes in an upstream persistent store or other explicitly governed process; a full refresh of current source values alone cannot reconstruct them. For hybrid Type 1/2 attributes, decide whether corrections affect all historical versions or just the current one. Check fact counts and totals before and after assigning keys; test boundaries, gaps, overlaps and late facts. Never use real customer data for this exercise.
Practice: validate the historical model
List the version key for each sales line and calculate segment totals for Type 1 and Type 2. Explain the treatment of a late January event and an event at the February boundary. Describe how an overlap and a missing historical version should be quarantined, and explain why total revenue alone cannot validate segment history.