Visual calculations in Power BI: DAX that lives on the visual
Visual calculations are now in preview in Power BI Desktop. What they are, when to pick them over a measure, and what the preview does not do yet.
A running total in DAX has always been a small rite of passage. You learn CALCULATE, you learn ALLSELECTED, you get the filter wrong twice, and then it works. With the February 2024 release of Power BI Desktop, Microsoft has put visual calculations into preview, and that same running total now takes one short line.
This is not just a new function. It is a new place to put calculations: on the visual, instead of in the semantic model. That is worth understanding before it spreads through your reports by accident.
What visual calculations are
A visual calculation is a DAX calculation that is defined and executed directly on a visual. It can refer to anything that is on that visual: columns, measures or other visual calculations. It cannot see anything else. If you want to use a field from the model, you add it to the visual first.
That restriction is the point. Because the calculation only works on what the visual already shows, you do not have to reason about filter context or relationships. Microsoft describes it as combining the simple context of calculated columns with the on-demand behaviour of measures.
Two more details matter:
- Visual calculations operate on the aggregated data in the visual, not on the detail level. Microsoft says this often gives performance benefits compared with a measure.
- By default, for most visuals, they are evaluated row by row over the visual matrix, much like a calculated column. You usually do not need to wrap references in SUM.
The running sum, before and after
The official announcement contrasts a classic running sum measure with the visual calculation version. Here are both, taken from that post:
RunningSum =
CALCULATE (
SUM ( 'Sales'[Sales Amount] ),
FILTER (
ALLSELECTED ( 'Date'[Fiscal Year] ),
ISONORAFTER ( 'Date'[Fiscal Year], MAX ( 'Date'[Fiscal Year] ), DESC )
)
)
RunningSumVisualCalculation = RUNNINGSUM([Sales Amount])
RUNNINGSUM is one of a set of functions that only work in visual calculations. Others include MOVINGAVERAGE, PREVIOUS, NEXT, FIRST, LAST, COLLAPSE, COLLAPSEALL and EXPAND. Microsoft describes them as shortcuts to the window functions OFFSET, INDEX and WINDOW that arrived in December 2022. If a shortcut does not behave exactly as you need, you can fall back to the window function.
Two optional parameters control how the calculation moves through the visual:
- Axis decides the direction: ROWS, COLUMNS, ROWS COLUMNS or COLUMNS ROWS. It defaults to the first axis, which for many visuals is ROWS.
- Reset decides when the calculation starts over: NONE (the default), HIGHESTPARENT, LOWESTPARENT or a number pointing at a level on the axis. With Year, Quarter and Month on the axis,
RUNNINGSUM([Sales Amount], HIGHESTPARENT)restarts every year.
Templates cover common cases such as moving average, percent of parent and versus previous.
When to use them instead of measures
After two decades in data, my rule of thumb for any new calculation option is simple: put logic where it will be reused, and keep it out of places where it will be copied.
Visual calculations fit well when:
- The calculation only makes sense in one visual, such as a running total down a specific table or a comparison to the previous row.
- The logic depends on the shape of the visual (what is on rows, what is on columns), which is awkward to express in a model measure.
- You want report authors to add simple analysis without asking the model owner for a new measure.
Measures are still the right choice when:
- The number is a business definition, like revenue or margin, that several reports must agree on.
- Other people build reports on your semantic model and need to find and reuse the calculation.
- You need relationships. Functions such as RELATED, RELATEDTABLE and USERELATIONSHIP are not available in visual calculations.
A useful test: if someone will ask "where is this number defined?", it belongs in the model.
What the preview does not do yet
This is a preview, and it is switched off by default. You enable it under Options and settings, Options, Preview features, tick visual calculations and restart Desktop. Then select a visual and use the New calculation button on the ribbon.
Plan around these gaps:
- A visual calculation lives on one visual. You cannot reuse it in another visual the way you reuse a measure.
- You can hide the fields a calculation depends on, but they still have to be on the visual.
- Several visual types are not supported, including slicers, R and Python visuals, Key Influencers, Decomposition Tree, Q&A and Smart Narrative.
- You cannot filter on a visual calculation, and conditional formatting is not supported on them in this preview.
- Visuals with visual calculations cannot be pinned to dashboards or used with Publish to web, and data exports do not include visual calculation results.
None of this is surprising for a first preview, and the team says more is planned. For now, I would keep visual calculations out of production reports that many people depend on.
What to do next
A sensible way to try it without creating a mess:
- Enable the preview on your own machine, not across the team.
- Pick a report with a running total or a "versus previous" measure.
- Rebuild it as a visual calculation and compare result and DAX side by side.
- List the measures that only exist to serve one visual. Those are the real candidates.
Takeaway
Visual calculations make a whole class of DAX much shorter and easier to read, and they work on aggregated data, which can help performance. The trade-off is that logic now lives in two places: the model and the visual. Decide early which calculations belong where, before your reports decide for you.
Which of your measures are really just visual calculations in disguise?
Sources
Enjoyed this? Get the next one by email
Occasional emails about Microsoft Fabric, SQL Server, Power BI and Synapse.