Data modeling · Beginner
What is the grain of a fact table, and why does it matter?
By Anurag Pandey, Lead Data Engineer ·
The short answer
The grain is exactly what one row of a fact table represents, for example one line on an order. You declare it before choosing dimensions or measures, because every row must be at the same grain or totals go wrong.
Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.
Say it like this
About 55 seconds out loud. Use it as a model, then put it in your own words.
The grain is the precise meaning of one row in a fact table. For a sales fact, it might be one row per product per order line, or one row per store per day. I declare the grain before anything else, because it decides which dimensions fit and which measures make sense. Kimball's design steps put it second, right after choosing the business process. I prefer the most detailed, atomic grain the source supports, because I can always roll it up later, but I can't break a daily total back into individual orders. The classic problem is mixing grains. If some rows are order lines and others are order totals, adding up revenue double counts. So when numbers look wrong, the first thing I check is whether every row really has the same grain.
What interviewers look for
- You define grain as what one row represents, with an example.
- You say the grain is declared before dimensions and facts.
- You explain the double-counting risk of mixed grains.
Common mistakes
- Describing grain as the level of detail in a vague way, without a concrete example.
- Choosing a summarised grain first and losing the ability to drill down.
- Mixing header-level and line-level measures in one fact table.
Follow-up questions to expect
- 1How would you model an order header and its order lines?
- 2What is a periodic snapshot fact table?
- 3How would you allocate a shipping charge to order lines?
Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.