Level 1: Model the data

Grain first

AI can't guess your grain.

What one row means, how to write it down in one line, and a two-query test that tells you whether that line is true.

Updated November 2026Example data, not from a client.
On this page
  1. What grain means
  2. Write it in one line
  3. Test the line
  4. One table, two grains
  5. Two facts, two grains
  6. What I check

Guide 1 ended on one line: check the grain first. This guide is about what that means when you sit down with a real model.

Grain is what one row in a table stands for. One revenue entry. One order line. One product per month. Every total, every join and every filter depends on it, and it's almost never written down. It lives in the head of whoever built the table.

People guess the grain from column names, and they're close enough most of the time. A tool that reads your model guesses too, and it can't walk over and ask the person who built it. If the grain isn't written down, it isn't part of the model.

What grain means

Here's the Revenue table from guide 1 again.

Revenue
PKidFKcustomerFKproductreporting dateaccounting dateamount
R-001C-001P-012025-04-012025-05-01120.00
R-002C-001P-012025-04-012025-04-01-20.00
R-003C-001P-012025-05-012025-05-01300.00

Revenue. Same three made-up rows as guide 1.

It's tempting to read it as one row per customer, product and month. It has a customer, a product and a date, and most reports show it by month. That reading is wrong. R-001 and R-002 are both C-001, P-01, April 2025. The real grain is one row per recognized revenue entry, and a month can hold any number of them, including a positive entry and a negative adjustment.

Why it matters: if you believe the grain is one row per customer, product and month, you'll treat the table like a lookup. You'll join other tables to it on those three columns, and every match you expected to be one row turns out to be two.

Write it down in one line

I use the same sentence for every fact table:

One row in [table] is one [thing], identified by [key]. It is not [the tempting wrong reading].

For the two tables in this series:

  • Revenue. One row in Revenue is one recognized revenue entry, identified by id. It is not one row per customer, product and month.
  • Terms. One row in Terms is one recorded contract term, identified by id. It is not one row per customer and product, and its amount is not revenue.

The "It is not" half does most of the work. It names the mistake somebody is going to make, before they make it.

Test the line

A grain statement is a claim about a key, so you can test it. If the key really identifies one row, grouping by it gives a count of 1 everywhere, and a query for counts above 1 comes back empty.

-- Claimed key: id. Expect no rows back.
SELECT id, COUNT(*) AS rows_per_key
FROM revenue
GROUP BY id
HAVING COUNT(*) > 1;

-- The tempting reading:
-- customer, product, month.
SELECT customer, product, reporting_date,
       COUNT(*) AS rows_per_key
FROM revenue
GROUP BY customer, product, reporting_date
HAVING COUNT(*) > 1;

The first query returns nothing, so id holds up. The second returns one row: C-001, P-01, 2025-04-01, with 2 rows per key. That's the tempting reading disproved with evidence, in two queries. (Every date in this example is the first of the month, so grouping by the date is the same as grouping by month.)

One table, two grains

The harder case is a table that holds two kinds of rows. Here's a made-up order table that keeps an order header and its lines together:

order_rows
PKrow_idorder_idrow_typeline_noamount
OR-1O-100header150.00
OR-2O-100line1100.00
OR-3O-100line250.00

Made-up order rows. The header carries the total; the lines carry the parts.

Sum the amount for O-100 and you get 300.00 for an order worth 150.00. Nothing errors, same as guide 1.

Figure 1 · One table, two grains

Mixed grain: an order header and its lines in one table Wrong: a made-up order_rows table holds the header row for order O-100 (150.00) and its two lines (100.00 and 50.00). Summing every row gives 300.00 for an order worth 150.00. All three are fact tables, tagged FACT. Right: split into an order headers table with one row, 150.00, and an order lines table with two rows that also sum to 150.00. WRONG · ONE TABLE, TWO GRAINS order_rows FACT O-100 · header 150.00 O-100 · line 1 100.00 O-100 · line 2 50.00 SUM over every row 300.00 The header already holds the order total. RIGHT · ONE GRAIN PER TABLE Order headers FACT O-100 150.00 Order lines FACT O-100 · 1 100.00 O-100 · 2 50.00 Header total = sum of lines 150.00 One row per order, or one row per line.
The header row already holds the total. Count it with its lines and the order doubles. Open full size

The same kind of test spots it. The claimed key for an order line is order_id plus line_no, and the header row has no line number. Count the rows where part of the claimed key is missing:

-- Claimed key for a line:
-- order_id + line_no.
SELECT row_type,
       COUNT(*) AS rows_missing_key
FROM order_rows
WHERE order_id IS NULL OR line_no IS NULL
GROUP BY row_type;

It returns one row: header, 1. Any rows back means the table holds more than one grain. A column called row_type, record_type or level is a warning sign on its own. The fix is to split it into one table of order headers and one of order lines. If you can't change the source, filter the model to one row type and say so in the grain statement.

Two facts, two grains

Sometimes each fact is fine on its own and they just sit at different grains. Say there's also a made-up monthly budget: one row per product per month, B-01, P-01, April 2025, 150.00, with no customer on it.

Don't join them row to row. Roll the finer table up to the coarser grain, then compare at that grain:

WITH actual AS (
  SELECT product, SUM(amount) AS actual
  FROM revenue
  WHERE reporting_date >= '2025-04-01'
    AND reporting_date <  '2025-05-01'
  GROUP BY product
)
SELECT b.product, b.month,
       a.actual, b.budget,
       a.actual - b.budget AS variance
FROM budget b
JOIN actual a ON a.product = b.product
WHERE b.month = '2025-04';

One row back: P-01, 2025-04, actual 100.00, budget 150.00, variance -50.00. In a Power BI or Tableau model it's the guide 1 shape again: both facts related to shared Product and Month dimensions, and nothing between the facts. Microsoft's star schema guidance covers the same idea for Power BI.

Figure 2 · Two facts, two grains

Two facts at two grains, joined through shared dimensions Revenue (PK id, FK customer, FK product, FK reporting_month, amount) relates many-to-one (zero or many to exactly one) to Customer, Product and Month. Budget (FK product, FK month, budget) relates many-to-one to Product and Month only, because budget has no customer. The two facts have no direct link and are compared only through Product and Month. Fact tables have dark headers tagged FACT and dimension tables have green headers tagged DIM. A legend shows the line-end marks: exactly one and zero or many. Revenue FACT PK id FK customer FK product FK reporting_month amount Customer DIM PK customer Product DIM PK product Month DIM PK month Budget FACT FK product FK month budget not on Budget Revenue: one row per entry. Budget: one row per product per month. They meet only through Product and Month. exactly one zero or many
Budget has no customer, so there's no line from Customer to Budget. That's a rule, not a gap. Open full size

One more rule falls out of the grain. Budget has no customer, so it can't be split by customer. A report that puts budget next to a customer slicer should show it as blank or say it doesn't apply. It shouldn't repeat 150.00 against every customer.

What I check before any tool answers from a model

  1. Does every fact table have a one-line grain statement, with an "It is not" half?
  2. Does the claimed key pass the uniqueness test?
  3. Does any row have part of its key missing, or a row-type column?
  4. When two facts meet, are they compared at the coarser grain, through shared dimensions?

Write the grain down. Then test it.

Building this in Power BI?

The Professional Harness gives your coding agent working PBIP examples and checks it reruns until they pass.

See the Professional Harness

Privacy

Related