Resolve the version at the sale
A customer has East valid up to May 1 and West from May 1.
The interview prompt
A customer has East valid up to May 1 and West from May 1. Three orders fall on April 30, May 1, and May 3. One arrives late. Show the regions, then introduce a bad overlapping dimension version and identify the affected orders.
Count matches before trusting the totals
Give the orders amounts of $10, $20, and $30. Using business-effective dates, East receives $10 and West $50. Grouping all three under the customer's current West region produces $60 in West. Say which report you are building before choosing the join. Arrival order has no bearing on a correctly defined effective-time lookup.
SELECT o.id, COUNT(d.version_key) AS matches
FROM orders AS o
LEFT JOIN customer_version AS d
ON d.customer_id = o.customer_id
AND d.valid_from <= o.order_day
AND (o.order_day < d.valid_to OR d.valid_to IS NULL)
GROUP BY o.id
HAVING COUNT(d.version_key) <> 1;
If someone extends the East end to May 2 without changing West’s start, the May 1 order now matches twice. Its $20 appears under both regions. Replacing the join with “pick the latest match” can hide corrupted intervals. Validate version history at ingestion, then separately verify that each observed fact resolved once. A customer with overlapping versions but no orders will escape a fact-only test.
The model behind the answer
A customer moves from East to West effective May 1. A May 3 order arrives in the warehouse on May 12. To analyze demand by the customer’s region when ordering, look up the version using May 3. Looking up the current customer row happens to work if the customer still lives in West. It fails as soon as another move intervenes.
Use a stable customer identity and a documented interval. One common join is valid_from <= order_time and order_time < valid_to, with an agreed treatment for an open end. Adjacent versions can then meet at midnight without both matching the boundary. Check that every order resolves once, and investigate gaps separately from overlaps.
The same table can also support a different business question. For a territory manager planning next quarter, regroup earlier orders under a specified current organization date via the durable identity. Label that date on the result so the grouping can be reproduced. Kimball on late-arriving facts
Try it in SQLite
A sale on the boundary
Compare the effective-time join with an inclusive end date. The $20 sale on May 1 exposes the duplicate.
Tables and sample data
Each run starts with fresh sample data. Use Ctrl+Enter or ⌘+Enter to run. Only your browser processes the query.
Catch a repair that hides overlapping versions
An agent proposes taking the latest matching dimension row to remove duplicate revenue. Supply the reviewer with an East row extended through May 1 and a West row starting May 1. Ask for the match-count diagnostic before the deduplication step.
Reviewer decision. The boundary order has two candidates. After repairing the interval, the three sales should yield East $10 and West $50, each with exactly one match. Keep the invalid history as a test that the pipeline can detect bad input even when the final report happens to look right.
Further reading. The Data Warehouse Toolkit, 3rd ed., on using the effective dimension on a late-arriving fact.
One more question
A category changes at noon and the model stores only dates. Can it classify morning and afternoon sales accurately?
Check your reasoning
Only if another source supplies the missing order or a legitimate business rule assigns the whole day to one version. A precise-looking interval expression cannot recover precision lost at capture. State the ambiguity or obtain timestamps.
Previous · Which changes deserve a new row · Next · Reproduce the report before the correction · Complete series map