Skip to content

Lesson 9 ยท Facts and Dimensions

Fact Table Types

Understand transaction, periodic snapshot, accumulating snapshot and factless fact tables, when to use each, and how to query them with runnable SQL.

Not every business question is about individual events. Sometimes you want the level of something at regular moments, or the progress of something that passes through stages. Dimensional modeling has standard fact table types for these cases. The type follows from the grain.

Three core types

Transaction One row per event
Periodic snapshot One row per period
Accumulating snapshot One row per process instance
1 / 2

Transaction fact tables

A transaction fact table has one row per measured event: a receipt line, a payment, a click. Rows appear only when something happens, and are normally not changed afterwards. If a correction is needed, many designs insert a reversing row so that history remains visible.

This is the most flexible type. If possible, keep it at the atomic grain.

Periodic snapshot fact tables

A periodic snapshot has one row per entity per period: stock per product per store per day, or account balance per month. A row exists even if nothing happened, because "still 12 tents in stock" is information.

You could derive stock levels from every movement ever made, but a snapshot makes the question simple and fast. It also catches changes that were never recorded as movements, if it is taken from a real stock count or the source's current balance.

Accumulating snapshot fact tables

An accumulating snapshot has one row per instance of a process with a known set of milestones, such as an order that is placed, paid, shipped and delivered. It has several date columns, and the row is updated as the order moves on. It makes durations between steps easy to measure.

It fits processes with a clear beginning and end. If steps repeat unpredictably, keep a transaction table of status changes too.

Compare them in SQL

SQL Three fact table types

Press Run (or Ctrl + Enter) to see the result here.

On 3 May there were no movements, yet the snapshot still has a row with 15 tents. Order O-2 has no delivery date, so its transit duration is NULL. That is correct: it is unknown, not zero.

In a full dimensional model, each date column in the accumulating snapshot would be a key to the date dimension, used in different roles. A common convention points a "not yet happened" key at a special dimension row instead of leaving it empty.

Factless fact tables

A factless fact table has keys but no natural numeric measure. There are two common uses:

  • Events: a student attended a class. You count rows.
  • Coverage: which products were on promotion in which stores on which days. Combined with sales, this answers "What was promoted but did not sell?", which a sales table alone cannot answer.
SQL Find promoted products that did not sell

Press Run (or Ctrl + Enter) to see the result here.

Using several types together

Process Likely tables
Orders Transaction lines, plus an accumulating snapshot of fulfilment
Inventory Movement transactions, plus daily snapshots
Bank accounts Transactions, plus monthly balance snapshots

Because the grains differ, keep them in separate tables and reconcile them. Snapshot changes should be explainable by transactions; a gap is worth investigating.

Design notes for each type

Transaction tables grow with business activity. Decide how corrections arrive. If a source edits a past sale, you can update the row, or insert a reversal and a corrected row. Reversals keep a visible trail, but row counts no longer equal the number of sales, so counts need a rule.

Periodic snapshots grow in a predictable way: entities multiplied by periods. With thousands of products, hundreds of stores and daily rows, that becomes large even when little happens. You might keep daily snapshots for the recent past and only month-end rows for older periods. Say so in the documentation, because daily questions about old periods can then no longer be answered from this table. Also decide what a missing snapshot means. A failed load must not be read as zero stock.

Accumulating snapshots need an update path. Your pipeline must find the existing row and fill in the next milestone. Think about unusual paths: an order that is canceled, delivered in two parts or returned before the delivery scan arrives. A status column and clear rules for each exception help. Averages of durations include only finished steps, so very slow orders that are still open are not counted. Report the number and age of open items next to the average.

Reconciling transactions and snapshots

When you hold both movements and snapshots, they should agree:

TEXT
previous level + movements in the period = current level

If they differ, possible causes include a missing movement, a stock count correction, theft or damage that was not recorded, or movements assigned to the wrong day. The difference itself can be useful information. Do not "fix" it by editing the snapshot to match.

Choosing with three questions

  1. Does the user ask about events? Use a transaction table.
  2. Does the user ask about a state at a point in time? Consider a periodic snapshot.
  3. Does the user ask how long a defined sequence of steps takes? Consider an accumulating snapshot.

If the answer is "all three", build more than one table from the same sources and reuse the same dimensions.

Document the type

In each fact table's description, state its type next to its grain. Add how rows arrive: appended only, inserted every period or updated in place. Analysts then know whether yesterday's query can return a different result today, and engineers know which loading and rerun strategy the table needs. For an accumulating snapshot, also list the milestones in their expected order.

Common mistakes

Do not add up a snapshot level across periods. Summing the four daily tent counts gives a number that means nothing as "stock". The next lesson explains why.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which table type has one row per product per day even when nothing changed?

    A periodic snapshot records the state at each period.
  2. 2. Which type is normally updated as a process reaches new milestones?

    Its single row per process instance gains milestone dates over time.
  3. 3. What can a promotion coverage factless table reveal that sales alone cannot?

    Sales rows exist only for things that sold, so coverage supplies what could have sold.
  4. 4. An order has no delivery date yet. What should its transit duration be?

    Zero would wrongly suggest instant delivery and distort averages.

Summary

  • Transaction facts record events; periodic snapshots record levels at regular times.
  • Accumulating snapshots follow one process instance through milestones and are updated.
  • Factless facts record events or coverage without a numeric measure.
  • Choose by grain, and combine types when a process needs several views.

Next: Measures and Additivity

Your progress is saved in this browser. No account needed.