Sub topic 9
What calculated columns cost in memory and refresh time
This chapter assumes you know Power BI Desktop's Report, Table and Model views, how a star-schema model fits together, and basic DAX such as SUM and IF. It also assumes you know that a calculated column is evaluated row by row and a measure is evaluated in the current filter context.
Where the cost comes from
A calculated column is computed when the model refreshes. Power BI stores the result in the model, just like a column loaded from the source. That stored result is the cost. A measure stores no values. It runs when a visual asks for it and leaves nothing behind.
Take this column on the Sales table:
Line Amount = Sales[Quantity] * Sales[Unit Price]If Sales has 50 million rows, this column adds 50 million stored values. The model compresses them, but they still occupy memory. They also have to be saved in the file or in the service.
The measure below gives the same total and adds no stored column:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])Memory: why cardinality matters
The engine behind Power BI is VertiPaq. It stores each column separately and compresses it. How well a column compresses depends mostly on its cardinality, which is the number of distinct values in it.
- A column with few distinct values, such as a "High" or "Standard" label, compresses very well.
- A column with many distinct values, such as a product of quantity and a decimal price, compresses poorly.
So Line Amount can be expensive on a large table, while a small text flag on the same table costs little. Row count matters too. The same formula on a 10,000-row dimension table is almost free.
Refresh time: the work is repeated
Every refresh recalculates every calculated column. Dependencies can add to this. A column that uses RELATED has to read from another table, and a column that depends on another calculated column is computed after it. Long chains of columns on a large table slow each refresh.
Product Category = RELATED(Product[Category])This column copies a text value into every Sales row. If you only need Category on a visual, the Product table already has it. A relationship filters Sales by Category with no extra column on Sales.
The trade-off
Measures are not free either. They shift the cost to query time. A heavy measure over a very large table can make a visual slow, and it is paid again each time a user changes a slicer. A calculated column pays once at refresh, so a visual that reads it is fast.
| Aspect | Calculated column | Measure |
|---|---|---|
| When computed | At refresh | At query time |
| Stored in model | Yes | No |
| Affects model size | Yes | No |
| Affects refresh time | Yes | No |
| Affects visual speed | Reads stored values | Computes each time |
Checking the cost
In Power BI Desktop, you can see how much space each column uses with DAX Studio or Tabular Editor, which can read the model's storage statistics. Look for large columns with high cardinality. These are the first candidates to remove or replace with a measure.
Exercise
Sales has 80 million rows. A teammate adds the calculated column Line Amount = Sales[Quantity] * Sales[Unit Price] only so a card visual can show total sales. Name two costs this adds and give a cheaper alternative.
Show answer
The column increases model size, because 80 million mostly distinct values compress poorly, and it lengthens every refresh, because it is recalculated each time. A cheaper alternative is the measure Total Sales = SUMX(Sales, Sales[Quantity] * Sales[Unit Price]), which stores nothing and is computed only when the card is rendered.