Periodic snapshot fact table
A fact table with one row per entity for each regular period, such as one row per account per month. Each row summarizes the period's activity or records a level at its end, and a row is written even when nothing happened.
Also: periodic snapshot · snapshot fact table · periodic snapshot table
On this page · 7 sections
- Category
- Data modeling
- Also known as
- periodic snapshot, snapshot fact table, periodic snapshot table
- Goes deeper in
- Data Modeling
A periodic snapshot fact table measures a process at fixed intervals. The grain is the period, not the event: one row per account per month, one row per product per warehouse per day. The row may summarize many underlying transactions, such as the number and value of deposits, or record a level at the end of the period, such as a balance or a stock quantity.
What sets the type apart is that it is predictably dense. In Ralph Kimball's description, a row is typically inserted for every entity in every period even if no activity took place, with a zero or null for each fact. A query can rely on every account appearing in every month, which a table of raw events cannot promise.
Snapshots usually sit beside a transaction fact table for the same process and do not replace it. The transactions hold the detail. The snapshot answers questions about level and trend, such as balance by month or stock on hand by day, that would otherwise mean adding up the full history of events for every date in the report.
select
m.month_key,
a.account_key,
count(t.transaction_id) as transaction_count,
coalesce(sum(t.amount), 0) as net_change,
sum(coalesce(sum(t.amount), 0)) over (
partition by a.account_key
order by m.month_key
) as month_end_balance
from dim_months m
cross join dim_accounts a
left join fct_account_transactions t
on t.account_key = a.account_key
and t.month_key = m.month_key
group by m.month_key, a.account_key
order by a.account_key, m.month_keyState questions become plain reads. Month-end balance by branch is a filter and a sum over snapshot rows, where the transaction table would need a running total from the day each account opened.
The facts in a snapshot are often semi-additive, which is the main way these tables produce wrong numbers. A balance can be added across accounts within one month and cannot be added across months.
- Summing a balance or inventory level across periods. Twelve month-end balances added together are not a yearly balance; use the last period, or an average.
- Skipping rows for entities with no activity, so an account disappears from the months in which it was idle and trend lines show gaps.
- Choosing a period shorter than the business reads. Daily snapshots of a figure that is reviewed monthly add roughly thirty times the rows and no new answers.
- What is an example of a periodic snapshot fact table?
- A monthly account snapshot in a bank: one row per account per month with the month-end balance, the number of transactions, and the fees charged. A daily inventory snapshot with quantity on hand per product per warehouse is the other standard example. In both, every entity gets a row every period.
- How is a periodic snapshot different from an accumulating snapshot?
- A periodic snapshot adds new rows on a calendar schedule and does not change the old ones, so the table grows by one set of rows each period. An accumulating snapshot has one row per process instance, such as an order, and updates that row as the order passes each milestone. One tracks levels over time; the other tracks progress through a pipeline.
- How do you build a periodic snapshot in SQL?
- Cross join the list of periods to the list of entities so every combination exists, left join the transactions for each period, and aggregate. Counts and sums become the period's activity facts, and a running total over the periods gives the ending level. In dbt it can be an incremental model that adds the newest period on each run.
