Sub topic 14
Why a star schema is smaller and faster
This chapter assumes you can load data in Power BI Desktop, read the Model view, write simple DAX measures, and tell a primary key from a foreign key. It explains why a star schema usually gives a smaller model and quicker queries than a single wide table. It also covers where that advantage can disappear.
How the engine stores your data
Power BI imports data into the VertiPaq engine. VertiPaq is a column-oriented, in-memory store. It keeps each column separately and compresses it on its own. It does not store whole rows together.
Three techniques do most of the compression work:
- Dictionary encoding. Each distinct value in a column is stored once in a dictionary. The column itself holds small integer references to dictionary entries.
- Value encoding. For numeric columns, the engine can store offsets from a base value, which needs fewer bits.
- Run-length encoding. When a sorted column repeats the same value many times in a row, the engine stores the value and a count instead of every repetition.
All three work best on columns with few distinct values. The number of distinct values in a column is its cardinality. Low cardinality compresses well. High cardinality compresses poorly and makes the dictionary large.
This is why model size depends on the number of distinct values in each column, more than on the number of rows or columns.
What a wide table costs
Suppose you load one flat table with one row per order line. Each row repeats the product name, subcategory, category, customer name, city, and country.
- Text attributes such as product name repeat on every row that sells that product. Dictionary encoding stores each distinct name once, but the column still holds one reference per row.
- Every descriptive column is as long as the fact table. A fact table with 50 million rows has 50 million entries in every attribute column.
- Some attribute columns end up with high cardinality, such as a free-text product description or a customer address. These make large dictionaries that are paid for once for every column that carries them.
In a star schema, the descriptive columns live in dimension tables. A product dimension with 2,000 products stores the product name 2,000 times, not 50 million times. The fact table keeps only a compact integer key for the product, plus the numeric columns.
Why integer keys help
The fact table's foreign keys should be integers, or other compact types. An integer key column has cardinality equal to the number of related dimension rows, and it compresses well. A long text key, such as a concatenated product code and name, has a bigger dictionary and costs more to compare.
The DateKey in the date dimension example from earlier chapters uses a whole number such as 20250131. This is cheaper than a text date and keeps the relationship column small.
Avoid a key column that is nearly unique on a large fact table unless you need it. Columns such as a transaction GUID or an order line identifier have a distinct value on almost every row. They cannot be compressed much, and the model rarely needs them for analysis. If you do not report on them, drop them from the model.
Removing columns and reducing precision
A star schema gives you a natural place to decide which columns belong. Some columns in a fact table cost more than they are worth:
- Unused columns. Remove any column that no visual, measure, or relationship uses.
- Calculated columns on the fact table. A calculated column is stored like any other column. A measure is computed at query time and takes no storage. Prefer a measure when you can aggregate the result.
- Excess precision. A
DateTimecolumn with seconds has far more distinct values than aDatecolumn. If reports only need the day, split or truncate the value. If you need the time of day, store it as a separate low-cardinality column, such as the hour. - Decimal places. A
Fixed decimal numbertype is more compact than a floating-point type for currency, and rounding to the precision you report gives fewer distinct values.
Why queries are faster
Size is half the story. The other half is how a query runs.
A visual that shows Total Sales by Category runs in two engines. The formula engine evaluates the DAX. The storage engine scans the compressed columns and returns aggregated data. In a star schema, the storage engine does this:
- Apply the filter on the
Categorycolumn in the small dimension. It scans a few thousand rows, not millions. - Find the matching dimension keys.
- Use the relationship to select the matching rows in the fact table.
- Sum
SalesAmountover those rows.
The expensive scan is the one over the narrow, compressed fact columns, and only the columns the query touches are read. Because the model is column-oriented, a wide table does not slow this query down by itself. Its cost comes from the larger attribute columns, which the engine must scan when it filters or groups on them. Filtering on a column that has 50 million entries takes longer than filtering on one with 2,000.
Relationships also reduce work for this reason: a one-to-many relationship from a dimension to a fact lets the engine propagate a filter through keys, using index structures built when the data loads.
-- The equivalent logic in SQL terms.
SELECT d.Category, SUM(f.SalesAmount) AS TotalSales
FROM FactSales AS f
JOIN DimProduct AS d
ON f.ProductKey = d.ProductKey
WHERE d.Category = 'Bikes'
GROUP BY d.Category;The SQL is only an analogy. VertiPaq does not run this statement, but the sequence of filter, match keys, and aggregate is similar.
Where the savings can disappear
A star schema is not automatically small. These mistakes bring the size back:
| Problem | Effect | Fix |
|---|---|---|
| Text columns copied into the fact table "for convenience" | Large repeated dictionaries and references | Keep text in dimensions and relate by key |
| A dimension with a very high row count, such as one row per transaction | The dimension becomes as large as the fact | Move the identifier to the fact as a degenerate dimension, or drop it |
| Bidirectional filters on many relationships | More work per query and possible ambiguous filter paths | Use single direction and write measures that handle the exception |
| Many-to-many relationships between large tables | Slower joins and results that are harder to reason about | Use a bridge table with one-to-many relationships |
| Snowflaked dimensions with long chains | Each hop adds a relationship the engine must follow | Flatten the chain into one dimension where it makes sense |
| Auto date/time left on for many date columns | A hidden date table is created for each date column | Turn it off and use one date dimension |
Auto date/time is worth special mention. When it is on, Power BI quietly builds a hidden calendar table for every date column in the model. On a model with several date columns, those tables add size and clutter. A shared date dimension, marked as a date table, replaces them all.
A worked comparison
Consider a sales model with 20 million order lines, 5,000 products, and 200,000 customers.
In the wide design, each of the 20 million rows carries ProductName, Category, CustomerName, and City. Each column has 20 million entries, even though Category has only a handful of distinct values.
In the star design, FactSales has ProductKey, CustomerKey, DateKey, Quantity, and SalesAmount. The 5,000 product names live once in DimProduct. The 200,000 customer names live once in DimCustomer.
The fact table still has 20 million rows, but its key columns are integers. In the star design, a slicer on Category reads the small dimension column. The wide design must scan the 20-million-row Category column. The exact savings depend on your data, so measure with VertiPaq Analyzer before and after the change.
Practical checklist
- Put descriptive text in dimensions and keep the fact table to keys and numbers.
- Use integer surrogate keys for relationships.
- Remove columns that nothing uses, and drop near-unique identifiers you do not analyze.
- Reduce date and decimal precision to what reports need.
- Prefer measures over calculated columns when a result can be aggregated.
- Keep relationships one-to-many and single direction.
- Replace auto date/time with one date dimension.
- Inspect the result with VertiPaq Analyzer.
Exercise
A fact table has 30 million rows and carries a text column ProductName with 4,000 distinct values. Explain why moving ProductName into a DimProduct table, related by an integer ProductKey, usually shrinks the model and speeds up a slicer on product name.
Show answer
In the fact table, the column holds 30 million references to the dictionary, one per row. After the move, the name is stored once per product, so the column has 4,000 entries. The fact table gains an integer ProductKey column, which compresses well because its cardinality is only 4,000. A slicer on product name now reads the 4,000-row dimension column instead of scanning 30 million entries, and the relationship carries the filter to the fact table through the key.
Exercise
Name two modeling choices that make a star schema larger or slower than it needs to be, and give the fix for each.
Show answer
Examples: a calculated column or text attribute copied into the fact table (fix: keep text in dimensions and use measures for aggregations), or a near-unique identifier column such as a transaction GUID that no report uses (fix: remove it from the model). Others that are also correct: bidirectional filters on many relationships (use single direction) and auto date/time on many date columns (use one date dimension).