Skip to content

Accumulating snapshot fact table

A fact table with one row per instance of a process that has a defined start and end, such as an order or an insurance claim. The row has a date for each milestone and is updated in place as the process moves from one step to the next.

Also: accumulating snapshot · accumulating snapshot table · accumulating fact table

On this page · 7 sections
  1. Definition
  2. Example
  3. Why it matters
  4. Common mistakes
  5. FAQ
  6. Go deeper
  7. Related terms

An accumulating snapshot fact table follows something through a pipeline. It suits processes with a clear beginning, a set of standard steps, and a clear end: an order that is placed, shipped, and delivered, or a claim that is filed, assessed, and paid. Each instance of the process gets one row, created when the process starts.

The row has a date foreign key for every milestone. Milestones that have not happened yet point to a placeholder row in the date dimension. When a step completes, the load goes back to the existing row and fills in that date. Ralph Kimball notes that this routine updating is unique among the three fact table types; the other two are loaded by adding rows.

Two kinds of fact usually sit beside the dates. Lag facts hold the elapsed time between milestones, such as days from order to shipment, so no query has to compute them. Completion counters hold 1 once a step is done and 0 before, so summing a counter gives the number of orders that have reached that step.

create table fct_order_fulfillment (
  order_id               integer primary key,     -- one row per order
  ordered_date_key       integer not null,
  shipped_date_key       integer not null,        -- 0 = not yet, a row in dim_dates
  delivered_date_key     integer not null,        -- 0 = not yet
  order_amount           numeric(10, 2) not null,
  order_to_ship_days     integer,                 -- lag fact, null until shipped
  order_to_delivery_days integer,                 -- lag fact, null until delivered
  shipped_count          integer not null,        -- 1 once shipped, else 0
  delivered_count        integer not null
);

-- A delivery is reported: revisit the order's row instead of adding one.
update fct_order_fulfillment
set
  delivered_date_key = (
    select d.delivered_date_key from stg_deliveries d
    where d.order_id = fct_order_fulfillment.order_id
  ),
  order_to_delivery_days = (
    select d.order_to_delivery_days from stg_deliveries d
    where d.order_id = fct_order_fulfillment.order_id
  ),
  delivered_count = 1
where delivered_count = 0
  and exists (
    select 1 from stg_deliveries d
    where d.order_id = fct_order_fulfillment.order_id
  );

select
  count(*) as orders,
  sum(shipped_count) as shipped,
  sum(delivered_count) as delivered,
  round(avg(order_to_ship_days), 1) as avg_days_to_ship
from fct_order_fulfillment;
A delivery report for one order updates its existing row. The sample table has four orders before and after the update; the summary then returns 4 orders, 3 shipped, 2 delivered, and an average of 2.0 days from order to shipment.
Why it matters

It answers questions about elapsed time directly. Average days from order to delivery, the share of claims paid within a target, and the number of orders stuck between two steps are all plain aggregates over one table.

The cost is in the load. Updating rows is harder than appending them: the job must find the existing row, cope with steps that arrive out of order, and run on warehouses and incremental strategies that favor inserts.

Common mistakes
  • Using the pattern for a process without fixed steps. If instances loop back, skip stages unpredictably, or have an open-ended number of events, one row cannot hold them; keep a transaction fact table of the events.
  • Leaving unreached milestone keys null, which drops those rows from any inner join to the date dimension. Point them at a row that means not yet.
  • Inserting a new row for each status change. That produces a table of status events under the wrong name, and every count of orders is inflated.
FAQ
What is an example of an accumulating snapshot fact table?
Order fulfillment is the standard one: one row per order line with the order date, ship date, delivery date, and payment date, plus the days between them. Insurance claims, loan applications, support tickets, and hiring pipelines fit the same shape, because each has a known first step, known intermediate steps, and a known last step.
Why are accumulating snapshot rows updated?
Because the row represents the whole life of one process instance, and that life is not over when the row is created. Each milestone adds information to the same row: a date, a lag, a counter. Keeping one row per instance is what makes counting orders and measuring time between steps a plain aggregate.
How do you build an accumulating snapshot in dbt?
One approach rebuilds the table on each run from the milestone events: pivot the events so each milestone date becomes a column, with one row per order. On large tables, an incremental model with a unique key on the order merges the changed rows instead. Either way the result is one row per instance with every milestone reached so far.