Articles

Star schema: what it is, why BI needs it and how to build one

Fact and dimension tables, grain, snowflake versus star, build steps, Power BI and Tableau, common mistakes. In plain words with examples.

10 min readSergiy Belyakov

The report is slow, its formulas fill half the screen, and the monthly total does not match the sum of the days. Very often the cause is neither the tool nor the analyst but the way the data under the report is arranged. The star schema is the most common and best-tested way to arrange data for analytics. It is used in data warehouses, Power BI, Tableau, Qlik and almost every BI tool.

Below: what it is, what it is made of, why it is needed, how to build it and where people most often trip up.

What a star schema is

A star schema splits data into two kinds of tables.

  • The fact table sits in the centre. It holds the events you measure: sales, payments, support requests, shipments. Each row is one event, and the columns hold numbers (quantity, amount, duration) and keys pointing to the dimensions.
  • Dimension tables sit around it. They are the lookups you analyse facts by: date, product, customer, store, employee. They hold descriptions: name, category, region, segment.

Each dimension is linked to the fact table one-to-many: one product appears in thousands of sales rows. Draw it on paper and the facts end up in the centre with the dimensions radiating out. Hence the name.

1∞1∞1∞1∞Salesfact tabledate keyproduct keycustomer keystore keyquantity, amountDatedimensionday, month, yearProductdimensionname, categoryCustomerdimensionsegment, regionStoredimensioncity, format
A star schema for sales: the fact table in the centre, four dimensions around it, each linked one-to-many.

Questions to such a model always take the same shape: filter the dimensions and aggregate the facts. "November revenue for the Drinks category in Kyiv stores" means: pick the November dates, the category in the product dimension and the city in the store dimension, then add up the amount in the sales table.

Facts and dimensions: how to tell them apart

Fact table Dimension table
What it stores events and numbers descriptions and attributes
Example columns date, product, customer, quantity, amount product name, category, brand, list price
Number of rows millions or more hundreds or thousands
How it grows new rows every day slowly, rows change
What reports do with it sum, count, average filter, group, label

A simple rule: if it makes sense to add a value up, it is a fact. If you group or filter by it, it is a dimension. The list price belongs in the product dimension; the actual sale amount belongs in the fact table.

Grain: what one row means

Before drawing tables, decide the grain of the fact table: what exactly one row means. For example, "one row is one line on a receipt" or "one row is the stock of a product in a warehouse at the end of the day".

The grain drives everything else. It determines which dimensions can be attached and which questions the model can answer. The most common modelling mistake is mixed grain: receipt lines and the monthly sales plan in the same table. A sum over such a table means nothing.

Prefer the finest grain available. Aggregates are easy to get from detail; detail cannot be recovered from aggregates.

Why use a star schema

  • It is easy to understand. Users see familiar words: products, customers, dates. They do not need to know how the source system works.
  • It is fast. BI engines (VertiPaq in Power BI, Hyper in Tableau, columnar warehouses) are optimised for this shape: narrow, long facts and short dimensions compress well and filter quickly.
  • Formulas become simple. A "Revenue" measure is the sum of one column, and slicing by any dimension works automatically. Without a star, the same measure gets rewritten for every report.
  • One version of the truth. Shared dimensions (one date table, one customer dimension for sales, payments and support) let you compare processes in one report, and the numbers agree.
  • History under control. Dimensions can keep a history of changes, for example which region a customer was in at the time of a sale.

Star, snowflake and one wide table

One wide table Star schema Snowflake schema
What it looks like everything in one table facts and flat dimensions dimensions split into sub-dimensions (product, category, group)
Ease for users high while columns are few high lower, more tables and relationships
Speed in BI good on small volumes best worse because of relationship chains
Model size large, descriptions repeat on every row moderate smallest
Several processes together hard, each process its own table easy through shared dimensions easy but more complex
When it fits quick analysis of one file the default for BI in a warehouse, when dimensions are large and change often

A snowflake is common and justified in a warehouse. In a BI tool's model, though, flatten the dimensions: product together with its category and group in one table.

How to build a star schema: six steps

  1. Pick a business process. Not "all company data" but one thing: sales, purchasing, support requests, shipments.
  2. Define the grain. What one fact row means. Write it down in one sentence.
  3. List the dimensions. Answer "who, what, where, when, how": customer, product, store, date, sales channel.
  4. Define the facts. Numbers describing the event at that grain: quantity, amount, discount, cost.
  5. Create keys and a date table. Each dimension has a unique key; facts hold only keys and numbers. The date table has every day with no gaps, with month, quarter, year and working days.
  6. Add an "Unknown" row. If a sale has no customer, its key points to an "Unknown customer" row instead of staying empty. Totals are not lost, and the problem is visible in the report.

For dimensions that change, decide up front whether history matters. If a customer moved from Kyiv to Lviv, you can overwrite the city (all old sales then "move" to Lviv) or add a new version of the row with validity dates (old sales stay in Kyiv). The second approach is known as a type 2 slowly changing dimension (SCD Type 2).

Star schema in Power BI and Tableau

Power BI. You can build the star in Power Query or take it ready-made from the warehouse. Then one-to-many relationships filtering in a single direction, a separate date table marked as a date table, and indicators as DAX measures rather than calculated columns. Bidirectional relationships only where there is no other way. More on the architecture around the model: BI architecture: four options.

Tableau. Prepare the star in the warehouse and, in Tableau, combine tables with logical-layer relationships: Tableau picks the joins each query needs and does not duplicate rows. Publish the model as a shared data source and connect workbooks to it. More: BI architecture on Tableau.

In both tools the star does the same job: an indicator is defined once, and reports only choose the slices.

Common mistakes

  • A relationship between two fact tables. Sales and returns are not joined directly; they are linked through shared dimensions: date, product, customer.
  • Mixed grain. Sales facts and the monthly plan in one table. Keep the plan in a separate fact table with a "month × product" grain.
  • Descriptions in the facts. A product name or customer address on every sales row bloats the model and drifts away from the dimension over time.
  • Duplicates in a dimension. If a customer appears twice, the one-to-many relationship breaks and customer counts in reports are inflated.
  • No date table. Without it, year-on-year comparisons, running totals and working days turn into complex formulas.
  • Many-to-many relationships everywhere. Sometimes they are needed, but usually they signal a missing bridge table or an imprecise grain.

Where to start

Take the report people use most and draw it on paper: what in it is a fact, what is a dimension, and what grain the facts have. Then try to phrase the three main questions to the report as "filter the dimensions and aggregate the facts". If you cannot, the model is worth rebuilding. I help with this as part of data architecture and business intelligence.

So how many tables in your model are linked to each other directly, bypassing the dimensions?

A similar problem in your team?

Describe the situation in a few sentences. I will reply with where I would start and whether I can help.

Discuss your project

Short weekly notes on data in the Telegram channel (in Ukrainian): @belyakovconsult

All articles

Glossary