Sub topic 1
What Visual Calculations Are and Why They Exist
Prerequisites
This chapter assumes you can create basic Power BI visuals, use tables and matrices, and write simple DAX measures with aggregations and DIVIDE.
What visual calculations are
A visual calculation is a DAX expression that runs on the data already displayed by one visual. It belongs to that visual rather than to the data model. This makes it useful for calculations that depend on the visual's order, groups, or hierarchy.
For example, a running total needs to know which row comes before the current row. A visual calculation can use that order directly.
Running sum = RUNNINGSUM([Sales Amount])The calculation is evaluated after the visual produces its rows, columns, and cells.
How they differ from measures and calculated columns
A measure is a reusable DAX expression stored in the model. It calculates when a visual queries the model and can be used across many visuals. A calculated column is computed for each row when the model refreshes and is stored in the table.
A visual calculation is created for one visual and works on that visual's displayed result.
| Calculation type | Defined in | Best for |
|---|---|---|
| Measure | Data model | Reusable business logic |
| Calculated column | Table | Row-by-row values |
| Visual calculation | One visual | Layout-aware analysis |
Use a measure when the logic must be consistent across reports or visuals. Use a visual calculation when the result mainly describes the current visual, such as a running sum or comparison with the previous row.
Thinking in the visual's rows and columns
Think of a matrix as a grid. Its row axis contains categories such as Year and Product. Its column axis might contain Month. Each cell is a value produced by the visual.
Functions such as RUNNINGSUM follow an axis. Functions such as PREVIOUS compare adjacent values on that axis. Therefore, sorting and hierarchy levels matter.
Creating your first visual calculation
- Select a visual in Power BI Desktop.
- In the visual's field list, open a field's context menu and choose New visual calculation.
- Enter a name and DAX expression in the calculation editor.
- Apply the expression and inspect the result.
- Sort the visual and test different filters to confirm the behavior.
Exercise
When should you choose a visual calculation instead of a measure?
Show answer
Choose it when the calculation depends on the selected visual's rows, columns, order, or hierarchy and does not need to be reused elsewhere.