Dimensional Modeling: How to Choose the Grain of a Fact Table

Grain is the most important decision when designing a fact table. Learn how to choose it, the types of fact tables, and common mistakes.

When designing a data warehouse with a star schema, the most important decision is not choosing tools, but declaring the grain of the fact table. The wrong grain means numbers cannot be summed correctly, reports cannot be drilled down, or tables bloat without benefit.

What is grain?

Grain is a statement of what one row in the fact table represents. Examples:

  • “One row = one product line item on one sales receipt.”
  • “One row = the balance of one account at the end of a day.”
  • “One row = one vehicle trip.”

The grain must be expressible in one clear sentence. If the team cannot agree on that sentence, the design is not ready.

The four steps of dimensional design

The widely used Kimball method defines four steps in order:

  1. Select the business process, such as sales, bill payment, or patient services.
  2. Declare the grain, meaning what one fact row represents.
  3. Identify the dimensions that describe that row: date, product, branch, customer.
  4. Identify the facts, the measured numbers: quantity, value, discount.

Note the order: grain is declared before choosing dimensions and facts. Dimensions and facts that do not fit the grain must be rejected or moved to another fact table.

The key principle: choose the most detailed grain

Whenever possible, use atomic data, the most detailed level available in the source system. Why:

  • Detailed data can be rolled up to any level (daily, monthly, by region). Summarized data cannot be broken back down.
  • New business questions often need details once thought unnecessary.
  • Modern analytical databases like ClickHouse can handle billions of detailed rows.

Aggregate tables can still be built to speed up dashboards, but as an addition, not a replacement for the detailed table.

Three types of fact tables

  • Transaction fact: one row per event, for example per sales line item. The most common and most detailed.
  • Periodic snapshot: one row per entity per period, such as daily account balances or weekly warehouse stock. Good for measuring status at a point in time.
  • Accumulating snapshot: one row per process with stages, such as one row per order with order date, ship date, and delivery date columns. The row is updated as each stage happens.

Example: choosing the grain for sales

A point-of-sale system stores receipts (header) and their items (detail). Grain options:

  • Per receipt: cannot answer “which product sells best?”. Too coarse.
  • Per line item: can answer by product, cashier, hour, and receipt. This is the right choice.

What about a shipping fee that only exists at receipt level? Either allocate it to each item using an agreed rule, or store it in a separate fact table with a per-receipt grain.

Common mistakes

  • Mixing grains in one table, such as line-item rows and receipt-total rows in the same table. Numbers get double-counted.
  • Storing header-level facts in a detail table without allocation, so the value is summed many times.
  • Summing semi-additive facts such as balances or stock over time. Balances can be summed across accounts but not across days; use period-end values or averages.
  • Starting from the requested report instead of the business process, so the fact table fits only one report.

Grain checklist

  • The grain can be written in one sentence and users agree with it.
  • Each dimension has exactly one value for every fact row.
  • Each fact matches the grain and does not come from a higher level.
  • The combination of dimension keys (or a transaction number) is unique per row.

Conclusion

Grain is the foundation of a fact table. Choose the business process, declare the grain as detailed as possible, then add the matching dimensions and facts. The right decision early on saves a lot of rework later.

Train your team to design data warehouses

Dimensional modeling is covered in depth, with case studies, in our data warehouse and BI workshop.

Leave a comment

Your email address will not be published. Required fields are marked *