← Problems75. Model a daily inventory snapshotMediumData Modelling
00:00 / 30:00

Model a daily inventory snapshot

MediumNot attempted yetAsked at Databricks

Warehouse stock is written to the lakehouse once a day per SKU. The question the business asks is always "what was on hand on this date" — and answering it by replaying every movement since the beginning of time is what a snapshot fact exists to avoid.

What the grader expects

dim_sku sku_key INTEGER sku_code VARCHAR fact_inventory_daily sku_key INTEGER as_of DATE on_hand INTEGER

Constraints

  • One row per SKU per day — the grain is the point of the table
  • on_hand is the level on that day, not the movement since the day before
  • The same SKU appears on many days and the same day carries many SKUs
  • The trap is a movements fact: it can answer "what changed" and cannot answer "what was on hand" without summing history every time

Example 1stock on the latest day

Input · dim_sku
sku_keysku_code
1AA-1
Input · fact_inventory_daily
as_ofon_handsku_key
2026-01-01101
2026-01-0271
Output
sku_codeon_hand
AA-17

Example 2many SKUs on the same day

Input · dim_sku
sku_keysku_code
1AA-1
2BB-2
Input · fact_inventory_daily
as_ofon_handsku_key
2026-02-0141
2026-02-0162
Output
total_on_hand
10

Topics

data modelingsnapshot fact

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Click a column, then another table’s column, to link them.

Start with a table. Give it a grain, then the columns that belong at that grain.

Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.