Sub topic 2
How Visual Calculations Differ from Measures and Calculated Columns
This chapter assumes you can build tables and matrices in Power BI Desktop, write basic DAX measures, and tell a measure from a column. It compares visual calculations with the two model-level calculation types you already know.
Three places to put a calculation
Power BI gives you three ways to add a DAX calculation. They differ in where the calculation lives, when it is evaluated, and what data it can see.
- A calculated column is stored in a table in the model. It is evaluated row by row when the data refreshes, and its results take up memory.
- A measure is stored in the model. It is evaluated at query time, in the filter context of each cell of a visual.
- A visual calculation is stored on one visual. It is evaluated against the data that the visual already holds, after the visual's query has run.
The last point is the main difference. A measure works from the model and the filters on each cell. A visual calculation works from the visual's result grid, so it can refer to rows and columns of that grid directly.
Comparison
| Aspect | Calculated column | Measure | Visual calculation |
|---|---|---|---|
| Lives in | A model table | The model | One visual |
| Evaluated | At data refresh | At query time, per cell | On the visual's result |
| Can refer to | Columns in the same table and related tables | Model columns, measures, tables | Fields in the visual, other visual calculations |
| Reusable in other visuals | Yes | Yes | No |
| Affects model size | Yes | No | No |
The same calculation both ways
Suppose a matrix shows Sales Amount by month. To get a running total with a measure, you must rebuild the filter context yourself:
Running total measure =
CALCULATE(
[Sales Amount],
FILTER(
ALL('Date'[Month Start]),
'Date'[Month Start] <= MAX('Date'[Month Start])
)
)The measure removes the month filter and then re-applies "all months up to the current one". This works, but you need to know the date table and the filter context well.
The visual calculation is one line:
Running sum = RUNNINGSUM([Sales Amount])It adds up the values already in the visual, in the order they appear. You do not name the date column, because the visual's layout supplies the order.
What this means in practice
Visual calculations are easier to write for tasks that depend on position: running totals, moving averages, and comparisons with the previous row. They do not add objects to the model, so a report author without model write access can still use them.
They also have costs.
- The result exists only in that visual. To use the same logic elsewhere, you must copy the visual or rewrite the calculation.
- Other visuals, slicers, and filters cannot use the result.
- The result depends on the layout. If you change which fields are in the visual, the calculation can change or stop working.
A measure is independent of any layout, so it gives the same answer wherever you place it.
Choosing at a glance
Exercise
A colleague wants a "Percent of grand total" figure in one matrix only. Another colleague wants a "Sales Amount in last 30 days" value that appears in three reports and in a slicer-driven card. Which calculation type fits each, and why?
Show answer
The first fits a visual calculation. It is tied to one matrix's layout and can be written with COLLAPSEALL. The second fits a measure, because it must be reused across reports and respond to filters. A calculated column is not suitable for either, since "last 30 days" changes with the date and the percent depends on visual context.