What's the Grain in the context of DW
Asked Answered
M

3

8

According to The Data Warehouse Toolkit by Kimball

"The grain must be declared before choosing dimensions
or facts because every candidate dimension or fact must be consistent with the grain."

I'm so confused about this concept .Could some one illustrate what's the meaning of Grain giving an analogy or metaphor in real life to clarify the concept .

Militarist answered 27/8, 2016 at 12:15 Comment(1)
Level at which the facts are measuredMonnet
V
10

Some examples:

  • "The sales table has a grain of DAY, STORE, PRODUCT"
  • "The sales table has a grain of DAY, STORE, PRODUCT, CUSTOMER"
  • "The sales table has a grain of HOUR, STORE, CUSTOMER"
  • "The sales summary table has a grain of DAY, STORE, PRODUCT_CLASS"

Hence the time dimension must support HOUR and DAY, and the product dimension must support PRODUCT and PRODUCT_CLASS.

Volution answered 27/8, 2016 at 12:29 Comment(3)
Just to add to David's post, I found this to be quite a helpful resource: kimballgroup.com/2003/03/declaring-the-grainChromatology
Hi, are not them the candidate Keys?Pendulum
@Enrique They would be if they combined to form a unique key, but in a DW fact table it would not be necessary that they do.Volution
W
9

The grain (or granularity of the fact) refers to the 'level' at which you're taking a measurement. A fact table describes a measurement taken of a business process, so the best way to describe the grain is to describe what you get for each row. The classic example for a supermarket checkout is 'one row for every beep/scan'. This is better than saying 'one row for every day, product and store' (i.e. naming the dimensions) because it grounds it in reality.

The grain/level element is that you might be storing a row at a level of product, or you might be storing it at some grouping of products. This matters as it will determine whether you can use the product-level dimension or the group-level dimension with it.

Watchmaker answered 22/2, 2017 at 23:3 Comment(0)
M
2

To add to David's examples. What if your Date dimension lowest grain is a week and Sales grain is a day? That means your DIM and FACT grain is inconsistent. Also, your sales table could point out a product and it's color, but what if the lowest grain of your Product dimension is just the product and no colors? Again there is an inconstancy in your DIM and FACT lowest grain.

Mouldy answered 15/9, 2016 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.