Start here
In the grain chapter you learned that every table has a grain: what one row means. This chapter builds tables for analytics on top of that idea.
A manager asks a question: what is the paid revenue for each country?
The answer needs two parts. One part is a number to add up: the order amount. The other part is a word to group by: the country.
Dimensional modeling keeps these two parts in two kinds of table.
- A fact table stores numbers about things that happened, with one row for each thing. An order is one such event.
- A dimension table stores the words that describe an event: who, what and when.
In the shop, the numbers are the order amount and the item quantity. The words are the customer, the product and the date.
The five tables
You will build five tables from the shop. The name starts with fact_ or dim_, so you can see the kind at once.
| Table | Kind | One row is |
|---|---|---|
| fact_orders | Fact | One order |
| fact_order_items | Fact | One item line on an order |
| dim_customer | Dimension | One customer |
| dim_product | Dimension | One product |
| dim_date | Dimension | One calendar day |
What you will learn
- What goes in a fact table, and which numbers you can add.
- What goes in a dimension table, and why the date gets its own.
- How a star query joins them.
- The four design steps, and what to do with missing values.
- How two fact tables share one dimension.
- Three special kinds of dimension: role-playing, junk and degenerate.
