The Data Foundry

← All practice

Data Modelling · Free · 25 min · Intermediate

Why did last month’s territory revenue change?

Write two territory reports from the same order lines: one at sale time and one at the supplied effective-as-of timestamp. Reconcile a backdated correction without losing or duplicating facts.

Original fictional teaching example. Uses SQLite in your browser; no warehouse update, sign-in, paid service or cloud completion.

Task and report rules

Prerequisites: SELECT, JOIN, GROUP BY, fact grain and UTC timestamp comparison. Finance wants territory at each sale; planning wants territory effective at 2026-02-15 00:00:00 UTC for every line.

Complete input data

Visible six-line fact with exact boundary, two lines in O2, and missing C3 dimension.

Selected source: 6 lines / 520 units. Each report must conserve this selected source.

Correction moves C1's North end and South start to 9 January at noon. Only O1's 100 units move historically; both reports still total six lines / 520 units. Selecting inputs preserves both query drafts and invalidates previous checks.

orders — order_id TEXT, line_id INTEGER, customer_id TEXT, sale_ts TEXT UTC, amount INTEGER

order_idline_idcustomer_idsale_tsamount
O01C12026-01-09 10:00:0060
O11C12026-01-09 23:59:59100
O21C12026-01-10 00:00:00200
O22C12026-01-10 00:00:0050
O31C22026-01-08 00:00:0080
O41C32026-01-11 00:00:0030

territory_history — customer_id TEXT, territory TEXT, valid_from TEXT UTC, valid_to TEXT UTC or NULL

customer_idterritoryvalid_fromvalid_to
C1North2026-01-01 00:00:002026-01-10 00:00:00
C1South2026-01-10 00:00:00NULL
C2West2026-01-01 00:00:00NULL

At sale time

Resolve territory using each order line's sale_ts.

As of 15 February

Resolve territory at 2026-02-15 00:00:00 UTC for every order line.

3-second query limit after engine load · 500 output rows · Cancel terminates execution

Run checks the selected disclosed snapshot. Both editors are independent.

Device-only drafts

Save both editors, snapshot and assistance state in this browser. No account or cloud save.

Loading this device's draft…

Help, in stages

Hints and the worked example are optional. Input data never requires reveal.