Sub topic 14
Limitations and choosing between visual calculations and measures
This chapter assumes you can build a matrix or chart in Power BI Desktop and write basic measures. It also assumes you have created a visual calculation with RUNNINGSUM, PREVIOUS, or COLLAPSE, and that you know a measure is evaluated in filter context while a calculated column is stored per row. The goal is to decide, for a given requirement, whether a visual calculation or a measure is the right tool.
What a visual calculation cannot see
A visual calculation runs against the data layout of one visual. That design makes it simple, but it sets the limits below.
- It sees only the visual's fields. The calculation can reference the measures and columns that are in the visual's field wells, including fields you have hidden. It cannot reference a table column or measure that is not in the visual. If you need that field, add it to the visual first. You can hide it afterwards.
- It lives inside one visual. Nothing in the semantic model stores the result. Other visuals, other reports, and other measures cannot use it. Copying the visual copies the calculation, but it creates a second independent definition.
- It depends on the visual's shape. The calculation sees rows, columns, and hierarchy levels. If someone adds a field, removes one, or swaps the axes, the same formula can return different numbers or an error.
- It does not change filter context. A measure can use CALCULATE to override filters. A visual calculation only reads the grid that the visual already computed. It cannot ask the model a new question.
- Support varies by visual and feature. Not every visual type, and not every surrounding feature, works with visual calculations. Microsoft's documentation keeps a current list of unsupported cases. Check that list before you build a design that depends on one.
Fragility: results follow the layout
Consider this calculation on a matrix with Year on rows:
Change vs previous = [Sales Amount] - PREVIOUS([Sales Amount])PREVIOUS looks at the prior row on the axis. With Year on rows, that is the prior year. If a colleague puts Region above Year in the row hierarchy, the previous row for the first year of each region is now blank, and the "previous" value for a region's first row is not the last year of the prior region. The formula did not change. The layout did.
A measure that computes the prior year through the date table does not have this problem, because it does not depend on how the visual is arranged.
Sales PY = CALCULATE([Sales Amount], SAMEPERIODLASTYEAR('Date'[Date]))
Change vs PY = [Sales Amount] - [Sales PY]This measure still depends on the model having a proper date table. It does not depend on the visual's row order, so it keeps working in any visual.
Side-by-side comparison
| Question | Visual calculation | Measure |
|---|---|---|
| Where is it defined? | On one visual | In the semantic model |
| Can other visuals reuse it? | No | Yes |
| Can other measures reference it? | No | Yes |
| Can it use fields not in the visual? | No | Yes |
| Can it change filter context? | No | Yes, with CALCULATE and filter functions |
| Does it depend on visual layout? | Yes, by design | No |
| Who can create it? | A report author with edit access to the visual | Someone who can edit the model |
| Typical strength | Running totals, moving averages, row-to-row comparisons, percent of parent | Reusable business logic, time intelligence, governed KPIs |
The percent of total case in detail
Percent of grand total is a good test case because both tools can do it.
As a visual calculation:
Percent of grand total = DIVIDE([Sales Amount], COLLAPSEALL([Sales Amount], ROWS))As a measure:
Percent of grand total (measure) =
DIVIDE([Sales Amount], CALCULATE([Sales Amount], ALLSELECTED()))The visual calculation is shorter and easier to read. Its denominator is always the top of the visual's row hierarchy, whatever the rows contain. The measure works in every visual, and you can pick exactly which filters it removes. ALLSELECTED keeps slicer and report filters. ALL would ignore them.
Use the visual calculation when one report page needs the number once. Use the measure when the same definition must appear across many reports and give the same answer.
Hidden fields and performance
Hiding a field in a visual only removes it from view. The visual still queries it, because the calculation needs it. Two consequences follow:
- A hidden field can still make the visual's query bigger. If you hide a high-cardinality column such as Order ID, the visual still returns a row for each of its values.
- Hidden fields are invisible to readers, so a later editor may not know a calculation depends on them. Name your calculations clearly, and keep the dependency obvious in the field wells.
Visual calculations often run faster than equivalent measures for window-style logic such as running totals. They operate on the already aggregated grid and do not re-evaluate the model for every row. This is a general tendency, not a guarantee. Test with Performance Analyzer if speed matters.
Common errors
- A blank or wrong first row. PREVIOUS has nothing to return on the first row of the axis, so the difference is blank or equals the full value. This is expected. Handle it with an explicit check if the blank is a problem.
- The calculation is "missing" after you change fields. The formula refers to a field you removed from the visual. Re-add the field and hide it if needed.
- The result changes when the hierarchy changes. COLLAPSE and COLLAPSEALL depend on the row hierarchy. Reordering the levels changes what "parent" means.
- A measure cannot find the visual calculation. Measures cannot reference visual calculations. Move the logic into a measure if another measure needs it.
- The same number looks different in two visuals. Two visuals with different layouts produce different results from the same formula. Compare layouts first.
A decision procedure
Ask the questions in order. The first "yes" decides.
Two further tests help in practice:
- The copy test. If you would copy the formula to a second visual, the logic probably belongs in the model.
- The layout test. If a change to the visual's fields should not change the meaning of the number, use a measure. If the number is meaningful because of the layout, such as "versus the row above", a visual calculation fits.
Mixed designs
The two tools combine well. A measure can provide the governed base value, such as [Sales Amount], and visual calculations then add presentation logic on top of it: running sums, moving averages, and shares of parent. This keeps the business definition in one place and keeps the report-specific logic in the report.
Exercise
A matrix shows Sales Amount by Region (rows) and Year (columns). You write Change vs previous = [Sales Amount] - PREVIOUS([Sales Amount]) and it works. A teammate then asks for the same "change vs prior year" number in three other reports and in a measure that flags regions with declining sales. Should you keep the visual calculation? Explain, and name the change you would make.
Show answer
No. Measures and other visuals cannot reference a visual calculation, and the result depends on this matrix's layout, so it would return different numbers if the rows or axes change. Create a measure in the model, for example Sales PY with CALCULATE and SAMEPERIODLASTYEAR on a date table, and Change vs PY as [Sales Amount] - [Sales PY]. Then reuse it in all reports and in the flagging measure.
Exercise
You hide a high-cardinality column such as Order ID in a visual because a visual calculation needs it. Does hiding it reduce the number of rows the visual queries? What risk does hiding it add for other report editors?
Show answer
No. Hiding removes the field from view only, so the visual still queries it and returns one row per Order ID value. The risk is that a later editor may remove or replace the hidden field without noticing that the calculation depends on it, which breaks the calculation.