Sub topic 15
Performance and Maintenance Tips
This chapter assumes you can navigate Power BI Desktop, understand a star-schema model, and write basic DAX such as SUM, IF and CALCULATE. It also assumes you know that calculated columns are computed at refresh time and measures at query time. Here we turn that knowledge into habits that keep a model fast and easy to maintain.
Keep Calculated Columns Few and Narrow
Each calculated column is stored in the model. It uses memory and adds work to every refresh. The cost depends on how many distinct values the column holds, because the engine compresses columns by their distinct values.
- A column with a few values, such as
Price Band, compresses well and costs little. - A column with a distinct value for almost every row, such as a concatenated key or a line amount with many decimals, compresses poorly.
Before you add a column, ask whether a measure can give the same answer. For a total, it often can:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])This measure stores nothing. The cost moves to query time, but the engine handles this kind of per-row arithmetic quickly. Keep the stored Line Amount column only if you need it as a field on a slicer or axis, or if it measurably speeds up a slow report.
Put Columns in the Right Table
A calculated column on a large fact table is repeated for every row. A column on a small dimension table is computed once per dimension row. When a value depends only on a product, put it on Product, as with Price Band, and let relationships carry it to the sales rows.
Use RELATED on the fact table only when you need the value there. Each RELATED column duplicates a dimension value across millions of rows.
Move Work Upstream When You Can
Calculated columns run after the data has loaded, inside the model. If the logic is a simple transformation, do it earlier:
- In the source query or a database view, if you can change it. The source does the work once, and every tool that reads it benefits.
- In Power Query, if you cannot. The result is still stored, but it is part of the load step and easier to compress and trace.
- In DAX, when the logic needs the model's relationships or runs at query time.
Write Measures for Reuse
Measures are cheap to store, so build them in layers. Define the basic totals once and reference them in other measures:
Total Sales = SUM(Sales[Line Amount])
Red Sales = CALCULATE([Total Sales], Product[Color] = "Red")
Red Share = DIVIDE([Red Sales], [Total Sales])If the definition of Total Sales changes, every dependent measure updates. Always use DIVIDE for ratios, because it handles a zero denominator without an error.
Maintenance Habits
| Habit | Why it helps |
|---|---|
| Create explicit measures and hide the raw numeric columns | Users pick the measure you tested, not an implicit sum of a column. |
| Store measures in a dedicated table | Report authors find them in one place. |
| Name ratio measures clearly, for example `Margin %` | Nobody confuses them with the row-level column. |
| Delete unused columns | Each one costs memory and refresh time. |
| Add a description to each measure | The logic stays clear for the next person. |
Measure Before You Optimize
Do not guess which objects are slow. Use Performance Analyzer in Power BI Desktop to see how long each visual takes. Use DAX Studio or VertiPaq Analyzer to see which columns use the most memory. Remove or redesign the largest columns first.
Exercise
A report has a calculated column Margin % (column) on a 10-million-row Sales table. Users average it in a visual and report the wrong overall margin. Also, the model refreshes slowly. What single change addresses both problems?
Show answer
Delete the column and create a measure, Margin % = DIVIDE(SUM(Sales[Profit]), SUM(Sales[Line Amount])). The measure divides the totals for the current filter context, so the ratio is correct at every level. Removing the column also cuts memory use and refresh time, because nothing is stored per row.