The report says 1,803.80. The true number is 1,644.40.
A sales report shows a number, the finance team shows a different one, and the meeting spends forty minutes on the difference instead of on the business. In many cases the cause is not a wrong formula in the report. It is a table where one row does not mean what everybody thinks it means, or where the same row was loaded twice. Every SUM on top of that table is then wrong, quietly and consistently.
This free first lesson is for analysts who build reports in Excel or Power BI, finance and controlling teams, and anyone who wants to understand how a data warehouse is organised before working with one. It covers the first decision in dimensional modelling, the one that every later step depends on: the grain of a fact table. You will learn to state it in one sentence, turn it into a key, and check with two formulas whether the data actually follows it.
We use the same fictional business as the lab above, Larkfield Home, a homeware retailer with six orders and fourteen loaded rows of sales data. Two of those rows are copies that a retried data load inserted a second time. Finding them is your job in the lab.
The core concept: facts, dimensions and the grain
Dimensional modelling, the approach made popular by Ralph Kimball, splits data into two kinds of tables. A fact table stores measurements of a business process: quantities, amounts, durations, counts. A dimension table stores the context you use to filter and group those measurements: the product with its category, the store with its region, the date with its month and quarter, the customer with their segment. Facts are long and narrow, with many rows and mostly numbers and keys. Dimensions are short and wide, with fewer rows and many descriptive columns.
Placed together, the fact table sits in the middle and every dimension links to it with a key. Drawn on paper it looks like a star, which is why this design is called a star schema. Reporting tools such as Power BI and the Excel Data Model are built to work with exactly this shape: filter a dimension, and the filter flows into the fact table along the key.
The grain answers the question: what exactly does one row of the fact table represent? For Larkfield Home's sales the answer is one row per order line. An order with three different products has three rows. Not one row per order, not one row per product per day, not one row per customer per month. Kimball's design process puts this decision second, right after choosing the business process and before choosing any dimension or measure, because everything else follows from it. Which dimensions can attach to a row depends on the grain, and which measures can be added up across rows depends on it as well.
A clearly stated grain gives you the key of the fact table for free. One row per order line means that the combination of order_id and line_no must be unique. Order 5003 has lines 1, 2 and 3, so 5003-1, 5003-2 and 5003-3 are three different rows. If 5003-2 appears twice, the table breaks its own grain, and every total that includes that order is too high.
Worked example: Larkfield Home's fact_sales
Here are the fourteen rows from the lab with the two helper columns filled in. Column F joins order_id and line_no into one grain key with =A2&"-"&B2. Column G counts how often each key appears in the whole column with =COUNTIF($F$2:$F$15,F2). Every value in G should be 1.
| Row | order_id | line_no | product_code | qty | net_amount | F: grain_key | G: rows_per_key |
|---|---|---|---|---|---|---|---|
| 2 | 5001 | 1 | LH-101 | 2 | 59.80 | 5001-1 | 1 |
| 3 | 5001 | 2 | LH-205 | 1 | 129.00 | 5001-2 | 1 |
| 4 | 5002 | 1 | LH-310 | 4 | 47.60 | 5002-1 | 1 |
| 5 | 5003 | 1 | LH-101 | 1 | 29.90 | 5003-1 | 1 |
| 6 | 5003 | 2 | LH-412 | 2 | 88.00 | 5003-2 | 2 |
| 7 | 5003 | 2 | LH-412 | 2 | 88.00 | 5003-2 | 2 |
| 8 | 5003 | 3 | LH-205 | 1 | 129.00 | 5003-3 | 1 |
| 9 | 5004 | 1 | LH-518 | 1 | 349.00 | 5004-1 | 1 |
| 10 | 5005 | 1 | LH-310 | 6 | 71.40 | 5005-1 | 2 |
| 11 | 5005 | 1 | LH-310 | 6 | 71.40 | 5005-1 | 2 |
| 12 | 5005 | 2 | LH-101 | 3 | 89.70 | 5005-2 | 1 |
| 13 | 5006 | 1 | LH-412 | 1 | 44.00 | 5006-1 | 1 |
| 14 | 5006 | 2 | LH-518 | 1 | 349.00 | 5006-2 | 1 |
| 15 | 5006 | 3 | LH-205 | 2 | 258.00 | 5006-3 | 1 |
Rows 6 and 7 are the same line of order 5003 (two units of LH-412 for 88.00), and rows 10 and 11 are the same line of order 5005 (six units of LH-310 for 71.40). Notice that the two copies are identical in every column. That is typical for a load that ran twice: the duplicate does not look wrong on its own, it only shows up when you count keys.
| Cell | Question | Formula | Result |
|---|---|---|---|
| E17 | Rows loaded | =COUNT(E2:E15) | 14 |
| E18 | Distinct order lines (the grain) | =SUMPRODUCT(1/COUNTIF(F2:F15,F2:F15)) | 12 |
| E19 | Net amount, duplicates removed | =SUMPRODUCT(E2:E15/G2:G15) | 1,644.40 |
| E20 | Net amount as loaded | =SUM(E2:E15) | 1,803.80 |
Three numbers tell the story. The table has 14 rows, but only 12 distinct order lines, which is the true number of facts at the declared grain. The net amount as loaded is 1,803.80, while the amount with each line counted once is 1,644.40. The difference, 159.40, is exactly the two duplicated lines (88.00 + 71.40). A report built on the raw table would overstate revenue by almost 10%.
How do the two one-cell formulas work? COUNTIF(F2:F15,F2:F15) returns an array with the count of every row's key: 1 for most rows, 2 for each copy of a duplicate. Dividing 1 by those counts gives 1 for unique rows and 1/2 for each of two copies, and SUMPRODUCT adds it all up, so a duplicated pair contributes 1/2 + 1/2 = 1. The amount formula uses the same idea: each amount divided by its row count, so the two copies of 88.00 contribute 44.00 each. In Excel 365 or 2021 you can also write =COUNTA(UNIQUE(F2:F15)) for the distinct count.
=SUMPRODUCT(1/COUNTIFS(A2:A15,A2:A15,B2:B15,B2:B15)), which works directly on the two key columns without a helper. Both give the same answer, the helper column is easier to read and to filter.How to do it in Excel, step by step
- Write the grain down. Before touching a formula, type one sentence in a note cell: "Grain: one row per order line (order_id + line_no)". If you cannot write this sentence, the table is not ready for reporting.
- Turn the data into a table. Click inside the data and press Ctrl+T. Structured tables extend formulas automatically when new rows arrive, which is exactly what you want for a check that runs after every load.
- Build the grain key. In F2 type
=A2&"-"&B2and fill down with a double-click on the fill handle. The hyphen matters: without it, order 500 line 11 and order 5001 line 1 would both become "50011". - Count each key. In G2 type
=COUNTIF($F$2:$F$15,F2). Press F4 while the range is selected to add the dollar signs, then fill down. - Make duplicates visible. Select F2:F15 and choose Home → Conditional Formatting → Highlight Cells Rules → Duplicate Values. Both copies of 5003-2 and 5005-1 turn red. Then press Ctrl+Shift+L and filter column G for values greater than 1.
- Add a one-cell test. Somewhere at the top of the sheet enter
=MAX(G2:G15)=1. It shows TRUE when the grain holds and FALSE after a bad load. A single cell like this is easy to check in a monthly routine. - Calculate both totals. Distinct lines:
=SUMPRODUCT(1/COUNTIF(F2:F15,F2:F15)). Duplicate-free amount:=SUMPRODUCT(E2:E15/G2:G15). Keep the raw=SUM(E2:E15)next to it so the gap is visible. - Fix the source, not just the sum. In a working copy, select the data and use Data → Data Tools → Remove Duplicates, ticking only order_id and line_no. In Power Query, select both columns and use Home → Remove Rows → Remove Duplicates. Then find out why the load ran twice, because the next one will.

Choosing the right grain
The usual advice is to choose the most detailed grain the source system offers, often called the atomic grain. Order lines can always be added up to orders, days, months or regions, but a table that only stores monthly totals per store can never answer a question about a single product. Detailed facts are also easier to check, because each row matches something a person can look up in the source system.
Different business processes need different grains, and each gets its own fact table. A transaction fact table has one row per event, such as an order line or a payment. A periodic snapshot has one row per item per period, such as stock on hand per product per day. An accumulating snapshot has one row per process instance that is updated as it moves along, such as an order from placement to delivery. Mixing grains in one table, for example order lines and order-level shipping fees in the same column, is a common source of double counting: the shipping fee repeats on every line and gets summed three times for a three-line order.
A good grain statement is short, uses business words and names the event, not the columns. A few examples show the pattern:
- Retail sales: one row per order line, key order_id + line_no.
- Bank transactions: one row per posted transaction, key transaction_id.
- Daily inventory: one row per product per warehouse per day, key product + warehouse + date.
- Support desk: one row per ticket status change, key ticket_id + change sequence number.
- Payroll: one row per employee per pay period per wage type, key employee + period + wage type.
Each statement immediately tells you which combination of columns must be unique, which dimensions make sense (a daily inventory row has a date and a warehouse, but no customer) and how to test the data. If two people on a team would write different sentences for the same table, settle that first. Arguments about report numbers later are almost always arguments about an unstated grain.
Common mistakes and how to spot them
- Using order_id alone as the key. One order has several lines, so
=COUNTIF($A$2:$A$15,A7)returns 4 for order 5003 even though nothing is wrong with three of those rows. Spot it: count the grain key, not part of it. - Joining keys without a separator.
=A2&B2can make different rows look identical once IDs have different lengths. Spot it: always put a hyphen or pipe between the parts. - Counting rows and calling it facts.
=COUNTA(F2:F15)returns 14 and includes the copies. Spot it: compare it with the distinct count; if they differ, the grain is broken. - Counting distinct orders instead of lines.
=SUMPRODUCT(1/COUNTIF(A2:A15,A2:A15))returns 6, the number of orders. Spot it: the distinct count must be at the declared grain. - Deleting rows that only look similar. Two different lines can legitimately have the same product, quantity and amount. Spot it: only rows with the same grain key are duplicates; check line_no before deleting anything.
- Hiding the problem with averages. An average order value calculated from duplicated rows looks plausible. Spot it: reconcile the total with the source system every month, which is exactly what lesson 8 of the course practises.
Quick reference: functions and shortcuts
| Function or shortcut | What it does | Example |
|---|---|---|
& | Joins values into one text, here the grain key | =A2&"-"&B2 → 5001-1 |
COUNTIF(range, value) | Counts how often a key occurs | =COUNTIF($F$2:$F$15,F2) |
COUNTIFS(r1,v1,r2,v2) | Counts rows matching several columns, no helper key needed | =COUNTIFS($A$2:$A$15,A2,$B$2:$B$15,B2) |
SUMPRODUCT(1/COUNTIF(…)) | Distinct count in one formula | Returns 12 for the lab |
COUNTA(UNIQUE(range)) | Distinct count in Excel 365 and 2021 | =COUNTA(UNIQUE(F2:F15)) |
SUMPRODUCT(E2:E15/G2:G15) | Total with every duplicate counted once | 1,644.40 |
MAX(G2:G15) | One-cell grain test: must be 1 | Returns 2 here |
| Home → Conditional Formatting → Duplicate Values | Colours every repeated grain key | Shows 5003-2 and 5005-1 |
| Data → Remove Duplicates | Deletes repeated rows for the selected columns | Tick order_id and line_no |
| Ctrl+T, Ctrl+Shift+L | Create a table, toggle filters | Filter rows_per_key > 1 |
Real-world uses
- Monthly sales reporting. Before a sales dashboard is refreshed, a one-cell grain test flags any load that inserted the same order lines twice, so wrong numbers never reach management.
- Migrating to Power BI. Moving from a flat Excel export to a star schema starts with stating the grain of every fact table. It decides which dimensions you can relate and prevents many-to-many surprises later.
- Finance reconciliations. Controllers reconcile revenue in the warehouse with the general ledger. Duplicate lines are one of the first things to rule out when the two do not match.
- Inventory and logistics. A stock table at one row per product per warehouse per day needs a three-part key. Checking that the key is unique catches double loads of daily stock files.
- Marketing and web analytics. Event tables (one row per click or session) are prone to duplicates when tracking fires twice. Counting a session-plus-event key reveals inflated conversion numbers.
What you will build in the rest of this course
This first lab is free. The remaining 19 labs belong to the full course, a one-time purchase of $9.90, and they build Larkfield Home's star schema piece by piece around the fact table you just checked.
Surrogate vs Natural Keys: Key Mapping and the Unknown Member. You replace the shop system's product codes with the warehouse's surrogate keys using XLOOKUP, send codes that are missing from the dimension to an Unknown member (-1) and measure how much revenue that affects.
Joining Facts to Dimensions: Enriching Sales with XLOOKUP and INDEX/MATCH. You join the sales facts to the product and store dimensions, bring in category, region and unit cost, and calculate the gross margin per line.
Aggregating by Dimension Attributes: SUMIFS by Category and Region. You turn the enriched rows into a category × region summary with SUMIFS, add totals and shares, and chart it as a stacked column chart.
The Date Dimension: Date Keys, Quarters, Months and Weekdays from a Date. You build the columns of a date dimension from plain dates with YEAR, MONTH, ROUNDUP and TEXT and use the quarter to summarise revenue.
Slowly Changing Dimensions Type 2: Valid-From/To and the Right Version by Date. Stores get re-zoned into new regions. You close old versions with a valid-to date and report each sale by the region that was valid when it happened.
Many-to-Many & Bridge Tables: Spotting Double Counting and Allocating with Weights. A product can belong to several collections. You measure how much a naive join double counts and allocate revenue with weights so the totals add up again.
Model QA: Orphan Keys, Inner-Join Losses and Reconciling Totals. You test the whole model like a data engineer: find fact rows without a matching dimension row, rebuild the report totals, reconcile them with the source system and chart the gaps.
Summary
A fact table stores measurements, dimension tables store the context, and together they form a star schema. The first and most important decision is the grain: what one row represents. For Larkfield Home it is one row per order line, so order_id plus line_no must be unique. A joined key with &, a COUNTIF per key and two SUMPRODUCT formulas reveal that the loaded table has 14 rows but only 12 real order lines, and that revenue is overstated by 159.40.
Now scroll up to the lab, build the grain key in column F, run the duplicate check in column G and calculate the distinct lines and the true net amount. It takes about fifteen minutes, the Coach checks each cell live, and you will never trust an unchecked SUM on a fact table again.
Frequently asked questions
What is the grain of a fact table?
The grain states exactly what one row of a fact table represents, for example one row per order line. It is decided before choosing dimensions and measures, and it defines which combination of columns must be unique.
What is the difference between a fact table and a dimension table?
A fact table stores measurements of a business process such as quantities and amounts, with keys to the dimensions. A dimension table stores descriptive context such as product category, store region or calendar month, used to filter and group the facts.
How do I find duplicate rows by key in Excel?
Build a key column, for example =A2&"-"&B2, and count each key with =COUNTIF($F$2:$F$15,F2). Any result above 1 is a duplicate. Conditional Formatting, Duplicate Values highlights them visually.
How do I count distinct values in Excel?
Use =SUMPRODUCT(1/COUNTIF(range,range)) in any Excel version, or =COUNTA(UNIQUE(range)) in Excel 365 and 2021. In a PivotTable added to the Data Model you can also choose Distinct Count as the value setting.
What is a star schema?
A star schema is a data model with one central fact table linked to several dimension tables by keys. It is the standard shape for reporting in tools such as Power BI and the Excel Data Model.
Why should a fact table use the most detailed grain?
Detailed rows can always be summed up to orders, months or regions, but summarised rows can never be broken down again. The most detailed grain keeps every question answerable and makes rows easy to check against the source system.
Keep going: Data Modeling Basics: Fact Tables, Dimensions, Keys & Star Schemas
This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time €9.90.
- Surrogate vs Natural Keys: Key Mapping and the Unknown Member
- Joining Facts to Dimensions: Enriching Sales with XLOOKUP and INDEX/MATCH
- Aggregating by Dimension Attributes: SUMIFS by Category and Region
- The Date Dimension: Date Keys, Quarters, Months and Weekdays from a Date
- Slowly Changing Dimensions Type 2: Valid-From/To and the Right Version by Date
- Many-to-Many & Bridge Tables: Spotting Double Counting and Allocating with Weights
- Model QA: Orphan Keys, Inner-Join Losses and Reconciling Totals
- Change Detection: Comparing the Source Extract with the Dimension (New, Changed, Unchanged)
- Type 1 vs Type 2 Reporting: Revenue as Was, Revenue as Is and the Restatement
- Periodic Snapshot Facts: Month-End Stock from Movements and the Semi-Additive Trap
- Accumulating Snapshot Facts: Order Milestones, Lag Days and Overdue Open Orders
- Factless Fact Tables: Promotion Coverage and the Products That Did Not Sell
- Junk & Degenerate Dimensions: Folding Flags into One Key and Keeping the Order Number
- Role-Playing Dimensions: One Date Dimension as Order Date and Ship Date
- Conformed Dimensions & Drill-Across: Sales and Returns by Category Without the Fan Trap
- Facts at Different Grains: Rolling Sales up to the Monthly Budget and Charting the Variance
- Aggregate Tables: A Monthly Summary, Its Reconciliation and the Distinct-Count Trap
- Non-Additive Measures: Margin %, Conversion Rate and Average Price in Summaries
- Final Project: Larkfield Home's Star-Schema Sales Dashboard with QA Checks