Sub topic 14
Choosing between a column and a measure
This chapter assumes you can move around Power BI Desktop (Report, Table and Model views). It also assumes you know a star-schema model and can read basic DAX such as SUM, IF and column references. Earlier chapters covered row context, filter context and when each object is evaluated. Here they become a decision procedure.
The two facts that drive every decision
Two facts decide almost every case:
- A calculated column is evaluated once per row at refresh time. Its results are stored in the model, take memory, and behave like any imported column.
- A measure is evaluated at query time, in the filter context of the visual cell that asks for it. It stores nothing and returns one value per cell.
Everything else follows from these. If you need a value to be a field (something you can put on a slicer, an axis, a filter or a sort), it must be a column. If you need a number to respond to whatever the user has selected, it must be a measure.
Question 1: Does the result need to be a field?
Slicers, chart axes, legends, table row headers, page filters and "sort by column" all need a column in a table. A measure cannot be placed on an axis or in a slicer.
Price Band = IF(Product[List Price] >= 100, "High", "Standard")This calculated column on the Product table gives you a field to drop on a slicer. No measure can do that job. If the answer to question 1 is yes, you need a column. The remaining question is where to build it, which is covered under "Where should the column be built?" below.
Question 2: Is the result an aggregation or a ratio?
If the value summarizes many rows, or if its correct total is not the sum of its parts, use a measure. Ratios are the classic case.
Margin % (column) = DIVIDE(Sales[Profit], Sales[Line Amount])This column is correct for each row. The problem appears when a visual summarizes it. Summing it adds percentages together, which is meaningless. Averaging it weights a 5-unit order the same as a 5,000-unit order, so the result is not the true overall margin.
Margin % = DIVIDE(SUM(Sales[Profit]), SUM(Sales[Line Amount]))The measure divides the totals for the current filter context. It is correct for a single product, a category, a year and the grand total, because each cell recomputes the ratio from its own sums.
The same logic applies to other non-additive values: distinct counts, averages, percent-of-total, year-over-year growth and running balances. Store the ingredients as columns if needed, and compute the result in a measure.
Question 3: Is the per-row value only a stepping stone?
Many columns exist only so a later SUM can add them up. The spine example shows this:
Line Amount = Sales[Quantity] * Sales[Unit Price]Total Sales = SUM(Sales[Line Amount])You can reach the same total without the stored column. SUMX creates a row context over Sales at query time:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])Both measures return the same number. The difference is cost, not correctness. The column version spends memory and refresh time to store one value per row. The SUMX version stores nothing and does the multiplication when queried. If nothing else needs Line Amount as a field, prefer SUMX. If many measures reuse Line Amount, or you want to see it in a table, the column is a reasonable choice.
Do not assume the column is faster at query time. The storage engine usually handles simple SUMX expressions over one table quickly. Test with a realistic data volume before deciding on performance grounds.
Question 4: Does the value come from another table?
A column can read from a related table with RELATED, following a many-to-one relationship from the many side:
Product Category = RELATED(Product[Category])This is a calculated column on Sales. It copies Category into every Sales row. In most star schemas you do not need it. Category already lives in the Product table, and a visual can slice Sales by Product[Category] through the relationship. Copying it into Sales duplicates data on the largest table in the model.
Add such a column only when you have a specific reason, for example a later calculated column on Sales that needs the category in its row context.
Where should the column be built?
When question 1 says you need a column, you have three places to build it.
| Location | Computed | Best when | Main drawback |
|---|---|---|---|
| Source (SQL view, warehouse) | At source, before load | Many reports need it, or the logic is heavy | Needs access to the source and a change process |
| Power Query | During refresh, before the model loads | Row-level cleanup or derivation from one table | Cannot reference model relationships or measures |
| DAX calculated column | After load, during refresh | Needs `RELATED`, other model columns or other DAX | Compressed less well, and is recalculated on every refresh |
A general rule is to push work as far upstream as practical. Columns from the source or Power Query compress with the rest of the imported table. They also keep the logic out of the DAX layer, where it is harder to find. Use a DAX calculated column when the logic depends on the model itself, such as a relationship, a value from another table, or another calculated column.
Power Query and the source are not suited to anything that must respond to slicers. That work still belongs in a measure.
Context transition: when a measure uses a column's row logic
A measure can call another measure inside a row context, and a row context turns into an equivalent filter context. This is called context transition. CALCULATE triggers it, and so does a measure reference, because Power BI wraps it in CALCULATE.
Red Sales = CALCULATE([Total Sales], Product[Color] = "Red")Here CALCULATE changes the filter context so only red products remain visible. This is how measures do work that people sometimes try to do with a column, such as flagging rows and then summing the flagged ones. A flag column is only needed if you want to slice by the flag.
Context transition inside a calculated column can be expensive. A column that calls a measure runs that measure once per row. On a large table, this slows refresh sharply. Be careful with this pattern.
A decision flow
Common mistakes
- Summing or averaging a row-level ratio column in a visual. Replace it with a measure that divides totals.
- Adding a calculated column only to feed a single
SUM. UseSUMXunless the column is reused. - Copying dimension attributes into the fact table with
RELATEDwhen the relationship already supports slicing. - Building a column that depends on a measure. It evaluates once per row and slows refresh.
- Using a calculated column for a value that must change with slicers. A column does not change after refresh. Use a measure.
Maintenance and size
Each calculated column adds storage and refresh work, and high-cardinality columns (many unique values) compress poorly. Before adding one, ask whether a measure would do. To review the cost of an existing model, check column sizes in an external tool such as DAX Studio or Tabular Editor, and remove columns that no visual, relationship or measure uses.
Name measures clearly and give them a home table, so report authors use your explicit measures instead of dragging a raw column into a visual and relying on implicit aggregation.
Exercise
A report has a column Discount % = DIVIDE(Sales[Discount], Sales[Line Amount]) on the Sales table. A table visual shows Discount % by Product Category, using Average of Discount %. The finance team says the figures do not match their own numbers. What is wrong, and what do you build instead?
Show answer
Averaging a row-level ratio gives every row equal weight, so small orders count as much as large ones. The result is not the true discount rate for the category. Build a measure that divides the totals in the current filter context: Discount % = DIVIDE(SUM(Sales[Discount]), SUM(Sales[Line Amount])). Then remove the column, or hide it, so nobody aggregates it by accident.
Exercise
Sales managers want to filter the report to "Premium" products, defined as List Price of 100 or more. Should you write a measure or a calculated column? Where would you build it?
Show answer
Filtering with a slicer needs a field, so it must be a column, not a measure. The rule uses only Product[List Price] in the same table, so build it in Power Query or the source if you can. If you prefer to keep it in the model, the DAX column Price Band = IF(Product[List Price] >= 100, "High", "Standard") on the Product table works. It is small because Product has few rows.
Exercise
A model has the calculated column Line Amount = Sales[Quantity] * Sales[Unit Price] and the measure Total Sales = SUM(Sales[Line Amount]). No visual uses Line Amount directly. How can you remove the column, and what is the trade-off?
Show answer
Replace the measure with Total Sales = SUMX(Sales, Sales[Quantity] * Sales[Unit Price]) and delete the column. This reduces model size and refresh time because the per-row product is no longer stored. The trade-off is that the multiplication runs at query time, and any other measure that used Line Amount must be changed as well. Test query speed with realistic data volumes.