# Fact table types explained: grain, transaction, periodic and accumulating snapshots

Every fact table answers one question: what does a single row mean? This guide declares the grain first, then builds the four classic fact table types in DuckDB, shows the double counting a mixed grain causes, and loads an accumulating snapshot with MERGE.

A star schema has two kinds of table. Dimensions describe things: products, customers, dates. Facts record what happened to those things: a sale, a stock count, a shipment. Most modelling mistakes that reach a dashboard are fact table mistakes, and most fact table mistakes come from one missing sentence: a clear statement of what a single row means.

That sentence is called the grain. This article teaches it first, then builds the four classic fact table types from the Kimball method in runnable [DuckDB](/tools/duckdb) SQL: transaction facts, periodic snapshots, accumulating snapshots and factless facts. Every table and number below comes from running the code. If you want the wider choice between modelling styles first, read [star schema, one big table or Data Vault](/articles/star-schema-one-big-table-vault); this article assumes you have chosen a star.

## What happened

Dimensional modelling is decades old, so the news here is in the tools you use to load it.

### DuckDB 2.0.0 LTS ships, and a patch changes how MERGE handles duplicate matches (21 October 2026)

DuckDB released version 2.0.0 as a long-term support release on 21 October 2026, supported until at least October 2027. Two parts matter for fact tables. It adds `BEFORE` and `AFTER` triggers with transition tables, which the announcement presents as a way to maintain summary tables incrementally. And it tried to give `MERGE` a well-defined result when several source rows match one target row. The announcement records that the 2.0.1 update reverted that change because of a performance regression, so a target row is again updated once per match, as in 1.x, with a proper fix planned for 2.1. The practical lesson, which applies to every engine, is to deduplicate the source of a `MERGE` before it reaches the fact table. The examples below do exactly that and were run on DuckDB 2.0.1.

## Grain: the one sentence every fact table needs

The Kimball Group puts it plainly: "The grain establishes exactly what a single fact table row represents." It calls declaring the grain "the pivotal step in a dimensional design" and says the declaration "becomes a binding contract on the design."

Think of a shop receipt. One receipt has a header (store, time, payment method, shipping fee) and several lines (product, quantity, price). "One row per receipt" and "one row per receipt line" are two different grains. Both are valid. Mixing them in one table is not, and the Kimball rule is blunt: "Different grains must not be mixed in the same fact table."

Kimball's four-step design process puts grain second, after choosing the business process and before choosing dimensions and facts:

1. **Pick the business process.** Selling, restocking, fulfilling orders.
2. **Declare the grain.** One row per order line; one row per product per day; one row per order.
3. **Identify the dimensions.** Whatever is true at that grain: date, product, store, customer.
4. **Identify the facts.** The numbers measured at that grain: quantity, amount, days to ship.

Prefer the most detailed, or atomic, grain you can. Kimball advises starting with atomic data "because it withstands the assault of unpredictable user queries." Microsoft's Fabric guidance makes the same point from the other side: you can always roll detail up, but "it's not easy to split out measure values to lower levels of granularity."

### How to tell facts apart: additivity

Facts differ in how they may be summed, and the fact table type usually decides which kind you get.

| Measure type | Can be summed across | Example | Safe aggregation |
|---|---|---|---|
| Additive | Every dimension | Units sold, net amount | `SUM` |
| Semi-additive | Some dimensions, not time | Stock on hand, account balance | `SUM` across products; last value or average across days |
| Non-additive | No dimension | Unit price, margin percentage | Store the parts, sum them, then divide |

For ratios, Kimball's advice is to "store the fully additive components" and compute the ratio only after summing them. Store discount amount and gross amount, never discount percentage alone.

## The four fact table types, built step by step

All four examples share two small dimensions: a date dimension for 1 to 5 November 2026 with integer keys such as `20261101`, plus one special row with key `-1` meaning "not happened yet", and a product dimension with a mug, a tea tin and a kettle. Surrogate keys and how dimensions change over time are covered in [slowly changing dimensions and surrogate keys](/articles/scd-type-2-surrogate-keys-asof).

```sql
CREATE TABLE dim_date AS
SELECT CAST(strftime(d, '%Y%m%d') AS INTEGER) AS date_key, CAST(d AS DATE) AS full_date
FROM range(DATE '2026-11-01', DATE '2026-11-06', INTERVAL 1 DAY) t(d);
INSERT INTO dim_date VALUES (-1, NULL);  -- "not happened yet"

CREATE TABLE dim_product (product_key INTEGER, sku VARCHAR, name VARCHAR);
INSERT INTO dim_product VALUES (1,'MUG-01','Mug'),(2,'TEA-01','Tea tin'),(3,'KET-01','Kettle');
```

### 1. Transaction fact table: one row per event

A transaction fact table records an event at the moment it happens. Microsoft's definition notes that "all the data is fully known when inserted, and it never changes (except to correct errors)." Its grain is usually the most atomic one available. Here the grain is one row per order line.

```sql
CREATE TABLE orders (order_id INTEGER, date_key INTEGER, shipping_fee DECIMAL(8,2));
INSERT INTO orders VALUES (101,20261101,10.00),(102,20261101,10.00),(103,20261103,10.00);

CREATE TABLE fact_sales (order_id INTEGER, line_no INTEGER, date_key INTEGER,
  product_key INTEGER, quantity INTEGER, net_amount DECIMAL(10,2));
INSERT INTO fact_sales VALUES
 (101,1,20261101,1,2,24.00),(101,2,20261101,2,1,8.00),
 (102,1,20261101,3,1,60.00),
 (103,1,20261103,1,1,12.00),(103,2,20261103,2,3,24.00),(103,3,20261103,3,1,60.00);

SELECT p.name, SUM(f.quantity) AS units, SUM(f.net_amount) AS revenue
FROM fact_sales f JOIN dim_product p USING (product_key)
GROUP BY p.name ORDER BY p.name;
```

| name | units | revenue |
|---|---|---|
| Kettle | 2 | 120.00 |
| Mug | 3 | 36.00 |
| Tea tin | 4 | 32.00 |

Both measures are additive, so any slice by date, product or order sums correctly. `order_id` stays in the fact table as a degenerate dimension: a key with no dimension table of its own, still useful for grouping lines back into orders.

**The mixed-grain trap.** The shipping fee belongs to the order, not the line. Join it to the lines and sum, and every multi-line order counts its fee once per line:

```sql
SELECT SUM(o.shipping_fee) AS shipping_wrong,
       (SELECT SUM(shipping_fee) FROM orders) AS shipping_right
FROM fact_sales f JOIN orders o USING (order_id);
```

| shipping_wrong | shipping_right |
|---|---|
| 60.00 | 30.00 |

The report doubles shipping revenue, and nothing errors. This is the same fan-out problem that semantic layers are built to prevent; see [how semantic layers stop fan-out](/articles/semantic-layer-fan-out-metricflow-measures). There are two clean fixes. Keep header facts in a separate fact table at order grain. Or allocate the header amount down to the line grain, here in proportion to line value:

```sql
SELECT f.order_id, f.line_no, f.net_amount,
  ROUND(o.shipping_fee * f.net_amount
        / SUM(f.net_amount) OVER (PARTITION BY f.order_id), 2) AS shipping_alloc
FROM fact_sales f JOIN orders o USING (order_id) ORDER BY 1, 2;
```

| order_id | line_no | net_amount | shipping_alloc |
|---|---|---|---|
| 101 | 1 | 24.00 | 7.50 |
| 101 | 2 | 8.00 | 2.50 |
| 102 | 1 | 60.00 | 10.00 |
| 103 | 1 | 12.00 | 1.25 |
| 103 | 2 | 24.00 | 2.50 |
| 103 | 3 | 60.00 | 6.25 |

The allocations sum to 30.00. With real prices rounding can leave a cent over or under, so production code usually assigns any remainder to the largest line.

### 2. Periodic snapshot: one row per thing per period

A periodic snapshot records the state of something at regular intervals: stock at close of day, balance at month end. Kimball's key sentence is "The grain is the period, not the individual transaction." These tables are "uniformly dense": a row exists for every product on every day, "even if no activity takes place during the period."

Density is what makes snapshots easy to query. Nobody has to replay history to learn the stock on 2 November; they read one row. We build the table from stock movements, using a date-by-product spine so that quiet days still get a row:

```sql
CREATE TABLE stock_movements (date_key INTEGER, product_key INTEGER, qty_change INTEGER);
INSERT INTO stock_movements VALUES
 (20261101,1,50),(20261101,2,40),(20261101,3,10),   -- opening receipts
 (20261101,1,-2),(20261101,2,-1),(20261101,3,-1),   -- sales on day 1
 (20261103,1,-1),(20261103,2,-3),(20261103,3,-1),   -- sales on day 3
 (20261104,3,5);                                    -- kettle restock

CREATE TABLE fact_inventory_daily AS
WITH spine AS (
  SELECT d.date_key, p.product_key
  FROM dim_date d CROSS JOIN dim_product p
  WHERE d.date_key > 0
),
daily AS (
  SELECT s.date_key, s.product_key, COALESCE(SUM(m.qty_change), 0) AS net_change
  FROM spine s LEFT JOIN stock_movements m USING (date_key, product_key)
  GROUP BY s.date_key, s.product_key
)
SELECT date_key, product_key, net_change,
  SUM(net_change) OVER (PARTITION BY product_key ORDER BY date_key) AS closing_qty
FROM daily;
```

The sales movements match the order lines in `fact_sales`. Five days times three products gives 15 rows. The kettle's rows show the density at work: 2 and 5 November have no movement but still carry a closing quantity.

| date_key | product_key | net_change | closing_qty |
|---|---|---|---|
| 20261101 | 3 | 9 | 9 |
| 20261102 | 3 | 0 | 9 |
| 20261103 | 3 | -1 | 8 |
| 20261104 | 3 | 5 | 13 |
| 20261105 | 3 | 0 | 13 |

**The semi-additive trap.** `closing_qty` can be summed across products on one day: total stock on 5 November is 96 units. It must not be summed across days.

```sql
SELECT p.name,
  SUM(closing_qty)                AS wrong_sum_over_days,
  arg_max(closing_qty, date_key)  AS closing_on_last_day,
  ROUND(AVG(closing_qty), 1)      AS avg_daily_stock,
  SUM(net_change)                 AS net_change_additive
FROM fact_inventory_daily f JOIN dim_product p USING (product_key)
GROUP BY p.name ORDER BY p.name;
```

| name | wrong_sum_over_days | closing_on_last_day | avg_daily_stock | net_change_additive |
|---|---|---|---|---|
| Kettle | 52 | 13 | 10.4 | 13 |
| Mug | 237 | 47 | 47.4 | 47 |
| Tea tin | 186 | 36 | 37.2 | 36 |

A naive "total stock this week" of 237 mugs is nonsense; the shop never held more than 48. The right answers are the closing value on the last day or the average daily stock, depending on the question. `net_change` is fully additive. Note that its sum equals the closing value only because stock started at zero. In a BI tool, define closing stock as a measure that takes the last date in the filter context rather than letting users drag the column into a sum.

### 3. Accumulating snapshot: one row per process, updated at each milestone

Some processes have a clear start, standard steps and an end: an order is placed, shipped and delivered. An accumulating snapshot keeps one row per process instance and fills it in as milestones occur. Kimball notes it has "a date foreign key in the fact table for each critical milestone" and that "the accumulating fact table row is revisited and updated", which makes it the only one of the three main types whose rows change in normal operation. It often carries lag measures, such as days between milestones, and milestone counters.

Microsoft's guidance describes the loading cycle: a row is loaded soon after the first event, then updated "in a predictable sequence every time a milestone event occurs." Milestones not reached yet hold an N/A state; here that is the `-1` date key.

```sql
CREATE TABLE fact_order_fulfilment (
  order_id INTEGER PRIMARY KEY,
  placed_date_key INTEGER, shipped_date_key INTEGER, delivered_date_key INTEGER,
  days_to_ship INTEGER, days_to_deliver INTEGER,
  milestones_done INTEGER, order_amount DECIMAL(10,2));

CREATE TABLE order_events (order_id INTEGER, event VARCHAR, event_date DATE);
```

The load is one `MERGE`. The source pivots all events seen so far into one row per order, which also guarantees no target row matches more than one source row:

```sql
MERGE INTO fact_order_fulfilment t
USING (
  SELECT e.order_id,
    MAX(CASE WHEN event='placed'    THEN event_date END) AS placed,
    MAX(CASE WHEN event='shipped'   THEN event_date END) AS shipped,
    MAX(CASE WHEN event='delivered' THEN event_date END) AS delivered,
    a.amount
  FROM order_events e
  JOIN (SELECT order_id, SUM(net_amount) AS amount
        FROM fact_sales GROUP BY order_id) a USING (order_id)
  GROUP BY e.order_id, a.amount
) s
ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET
  shipped_date_key   = COALESCE(CAST(strftime(s.shipped,   '%Y%m%d') AS INTEGER), -1),
  delivered_date_key = COALESCE(CAST(strftime(s.delivered, '%Y%m%d') AS INTEGER), -1),
  days_to_ship    = date_diff('day', s.placed, s.shipped),
  days_to_deliver = date_diff('day', s.placed, s.delivered),
  milestones_done = 1 + (s.shipped IS NOT NULL)::INT + (s.delivered IS NOT NULL)::INT
WHEN NOT MATCHED THEN INSERT VALUES (
  s.order_id,
  CAST(strftime(s.placed, '%Y%m%d') AS INTEGER),
  COALESCE(CAST(strftime(s.shipped,   '%Y%m%d') AS INTEGER), -1),
  COALESCE(CAST(strftime(s.delivered, '%Y%m%d') AS INTEGER), -1),
  date_diff('day', s.placed, s.shipped),
  date_diff('day', s.placed, s.delivered),
  1 + (s.shipped IS NOT NULL)::INT + (s.delivered IS NOT NULL)::INT,
  s.amount);
```

We feed events in three daily batches and run the same `MERGE` after each. Batch 1 places orders 101 and 102. Batch 2 ships 101 and places 103. Batch 3 delivers 101 and ships 102 and 103. The table after batch 3:

| order_id | placed | shipped | delivered | days_to_ship | days_to_deliver | done | order_amount |
|---|---|---|---|---|---|---|---|
| 101 | 20261101 | 20261102 | 20261104 | 1 | 3 | 3 | 32.00 |
| 102 | 20261101 | 20261104 | -1 | 3 | NULL | 2 | 60.00 |
| 103 | 20261103 | 20261104 | -1 | 1 | NULL | 2 | 96.00 |

After batch 1 the same table held two rows with `-1` in both later date keys and one milestone each; after batch 2, order 101 showed `days_to_ship` of 1. Running the `MERGE` a fourth time with no new events leaves the table unchanged: 3 rows, 7 milestones in total. That idempotence is what makes reruns and backfills safe, a theme covered in [idempotent batch jobs](/articles/idempotent-batch-jobs-partition-overwrite-backfills).

The questions this table answers in one pass are pipeline questions: average days to ship (1.67 here), how many orders are still awaiting delivery (2), which orders are stuck. Answering them from a transaction table needs self-joins across event rows.

Two design notes. Lag columns are left `NULL` until both milestones exist, so `AVG` ignores unfinished orders instead of counting them as zero. And the `-1` key joins to a real dimension row, so inner joins to `dim_date` never silently drop open orders.

### 4. Factless fact table: events with no numbers

Sometimes an event has no measure at all: a student attends a class, a product is on promotion on a day. Kimball calls this a factless fact table, one that "merely records a set of dimensional entities coming together at a moment in time." You measure it by counting rows.

Its most useful trick is analysing what did not happen. Kimball describes a coverage table of everything that might happen and an activity table of what did: "When the activity is subtracted from the coverage, the result is the set of events that did not happen."

```sql
CREATE TABLE fact_promotion_coverage (date_key INTEGER, product_key INTEGER, promo_code VARCHAR);
INSERT INTO fact_promotion_coverage VALUES
 (20261101,1,'NOV10'),(20261101,3,'NOV10'),
 (20261103,2,'TEA3'),(20261103,3,'NOV10'),
 (20261104,1,'NOV10'),(20261104,2,'TEA3');

-- Promoted products that sold nothing that day
SELECT c.date_key, p.name, c.promo_code
FROM fact_promotion_coverage c
JOIN dim_product p USING (product_key)
WHERE NOT EXISTS (
  SELECT 1 FROM fact_sales s
  WHERE s.date_key = c.date_key AND s.product_key = c.product_key)
ORDER BY c.date_key, p.name;
```

| date_key | name | promo_code |
|---|---|---|
| 20261104 | Mug | NOV10 |
| 20261104 | Tea tin | TEA3 |

The sales table alone can never show this: a promotion with no sales leaves no sales row. Counting coverage rows also gives "promotion days": 4 for NOV10 and 2 for TEA3.

## Choosing the type

| Question you need to answer | Type | Grain example | Rows change? | Typical measures |
|---|---|---|---|---|
| What happened, in full detail? | Transaction | One row per order line | No, except corrections | Additive: quantity, amount |
| What was the level at a point in time? | Periodic snapshot | One row per product per day | No, new rows each period | Semi-additive: balance, stock |
| How far has each case progressed, and how fast? | Accumulating snapshot | One row per order | Yes, at each milestone | Lags, milestone counts |
| Which combinations occurred, or failed to? | Factless | One row per product per promotion day | No | Row counts |

Most mature models use several types for one business area. An order process might have a transaction fact for order lines, an accumulating snapshot for fulfilment, and a daily snapshot of open orders, each at its own grain and each a separate table, as Kimball requires: "Each proposed fact table grain results in a separate physical table." In a [medallion architecture](/articles/medallion-architecture-quality-gates-reprocessing) these fact tables live in the [gold layer](/tools/gold-layer).

## What it means in practice

Write the grain down before writing SQL, in a comment at the top of the model or in the model's documentation: "one row per order line, as of the moment the line was created". It turns code review from "does this look right?" into "does each column belong at this grain?", which is a question with an answer.

Expect most dashboard errors to come from two places shown above: header values repeated across line rows, and semi-additive balances summed over time. Neither produces an error message. Both are caught by tests that compare a fact table total with an independent source, such as the sum of order headers.

Accumulating snapshots are the type teams avoid longest, because their rows are updated. With a deduplicated `MERGE` and a rerunnable source, as above, they are no harder to load than an incremental model; [dbt incremental models](/articles/dbt-incremental-models-microbatch-backfills) cover the same merge strategy in dbt.

## What to do now

1. **Write the grain sentence.** For every fact table, state what one row means, in plain words, in the model's documentation.
2. **Test the grain as a unique key.** Assert that the grain columns are unique, for example `order_id, line_no` for order lines.
3. **Move header facts out of line tables.** Give order-level amounts their own fact table or allocate them, and test that totals match the source.
4. **Label semi-additive measures.** Mark balances and stock levels in your semantic layer so they use last value or average over time.
5. **Build snapshots from a spine.** Cross join dates and entities first so quiet periods still get a row.
6. **Use a not-yet key for open milestones.** Point unreached dates at a `-1` dimension row instead of `NULL` so joins keep open cases.
7. **Deduplicate every MERGE source.** Pivot or aggregate to one row per target key before merging, whatever your engine.
8. **Prove reruns are harmless.** Run each load twice in a test and assert the fact table is unchanged.
9. **Record non-events where they matter.** Add coverage tables for promotions, schedules or assignments you need to report on.

## Risks and open questions

**Atomic grain costs storage and compute.** Order lines can be hundreds of times more rows than daily totals. Keep the atomic table and add aggregate tables for speed rather than replacing detail with summaries.

**Late events reorder milestones.** A delivery event can arrive before its shipment event after a system outage. The pivot-then-merge pattern copes because it recomputes from all events, but lag measures can briefly be negative or missing; add a test for negative lags.

**Snapshots grow fast.** A daily snapshot of a million products adds a million rows a day whether anything happened or not. Monthly snapshots, or daily ones kept only for a rolling window, are common compromises.

**Engine behaviour differs on MERGE.** Engines handle several source rows matching one target row differently, and DuckDB itself changed and then restored its behaviour between 2.0.0 and 2.0.1. Do not rely on any engine's handling of duplicates.

**Watch next:** DuckDB's planned fix for multi-match `MERGE` in version 2.1, and whether its new triggers become a practical way to maintain aggregate fact tables incrementally.

## Frequently asked questions

### What is the grain of a fact table?

The grain is a precise statement of what one row represents, such as one row per order line or one row per product per day. Kimball calls declaring it the pivotal step in dimensional design. Every dimension and measure in the table must be true at that grain.

### Can I put order-level and line-level facts in the same table?

Not safely. Order-level values such as a shipping fee repeat on every line, and summing them over-counts, as the example shows by reporting 60.00 instead of 30.00. Put them in an order-grain fact table or allocate them down to lines so they sum correctly.

### Why can't I sum stock levels over time?

Stock on hand is a semi-additive measure: it adds up across products on one day, but each day's value already includes all earlier movements. Summing five daily balances counts the same units up to five times. Use the closing value for the period, or the average daily level.

### When should I use an accumulating snapshot instead of a transaction table?

Use one when the business asks how far each case has progressed and how long each step takes, for a process with known milestones such as order fulfilment or claims. One row per case with a date key per milestone makes lags and backlogs simple queries. Keep the transaction table too for event-level detail.

### What is a factless fact table used for?

It records that dimensions met at a point in time, such as attendance or promotion coverage, without any numeric measure. You analyse it by counting rows. Comparing a coverage table with an activity table reveals events that did not happen, such as promoted products with no sales.

## Summary

A fact table is defined by its grain, the one sentence that says what each row means, and mixing grains is the root of the most common silent reporting errors. Transaction facts record events at atomic grain with additive measures. Periodic snapshots record levels per period, densely, with semi-additive measures that must not be summed over time. Accumulating snapshots keep one row per process and are updated at each milestone, best loaded with a deduplicated, rerunnable `MERGE`. Factless facts record combinations without numbers and, paired with coverage tables, reveal what did not happen. Choose the type from the question you need to answer, and give each grain its own table.

## Sources

- [Kimball Group: Grain](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/grain/)
- [Kimball Group: Periodic snapshot fact tables](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/periodic-snapshot-fact-table/)
- [Kimball Group: Accumulating snapshot fact tables](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/accumulating-snapshot-fact-table/)
- [Kimball Group: Factless fact tables](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/factless-fact-table/)
- [Kimball Group: Additive, semi-additive and non-additive facts](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/additive-semi-additive-non-additive-fact/)
- [Microsoft Learn: Dimensional modeling in Fabric Data Warehouse, fact tables](https://learn.microsoft.com/en-us/fabric/data-warehouse/dimensional-modeling-fact-tables)
- [DuckDB: MERGE INTO statement](https://duckdb.org/docs/2.0/sql/statements/merge_into.html)
- [DuckDB: Announcing DuckDB 2.0.0 LTS](https://duckdb.org/2026/10/21/announcing-duckdb-200)
