Power BI Exercise - Reusing Calculations with a Calculation Group
Power BI Exercise - Reusing Calculations with a Calculation Group
Define calculation logic once and apply it to multiple retail measures.
In this guided exercise, you will create a Calculation Group containing three reusable calculation items: Value, Percentage of Category Total, and Running Total. The same logic will work with both Total Sales and Total Quantity.
SELECTEDMEASURE().
Why use a Calculation Group?
Without a Calculation Group, you might create separate measures for Sales Percentage, Quantity Percentage, Sales Running Total, and Quantity Running Total. The number of measures grows whenever the same calculation pattern must be repeated.
A Calculation Group defines the transformation once. SELECTEDMEASURE() acts as a placeholder for whichever explicit measure is currently being evaluated.
Calculation items transform measures; they do not replace the base measures.
Before you begin
Use the completed retail star-schema model. Confirm that these explicit measures exist:
Total Sales = SUM ( Sales[SalesAmount] )
Total Quantity = SUM ( Sales[Quantity] )
Important model change
Calculation items apply only to explicit measures. When you add a Calculation Group, Power BI enables Discourage implicit measures. This prevents report authors from dragging numeric columns directly into Values and relying on automatic Sum or Average aggregation.
Step 1: Create the Calculation Group
- Open Model view.
- On the ribbon, select Calculation group.
- If prompted to enable Discourage implicit measures, select Yes.
- Rename the new Calculation Group to Reusable Calculations.
- Rename its calculation-group column to Calculation.
Power BI creates the first calculation item automatically.
Step 2: Create the Value calculation item
- Rename the first calculation item to Value.
- Enter this expression in the DAX formula bar:
SELECTEDMEASURE ()
Value returns the original result and preserves the base measure's formatting.
Step 3: Create Percentage of Category Total
- Right-click the Calculation items section and select New calculation item.
- Name it % of Category Total.
- Enter this expression:
DIVIDE (
SELECTEDMEASURE (),
CALCULATE (
SELECTEDMEASURE (),
REMOVEFILTERS ( DimProduct[Category] )
)
)
The numerator keeps the current category. The denominator removes only Category, while retaining other filters such as Region, Channel, and Date.
Step 4: Apply a dynamic percentage format
- Select the % of Category Total calculation item.
- In the Properties pane, enable Dynamic format string.
- Enter:
"0.00%"
The result remains numeric but is displayed as a percentage.
Step 5: Create Running Total
- Create another calculation item named Running Total.
- Enter:
CALCULATE (
SELECTEDMEASURE (),
FILTER (
ALLSELECTED ( 'Date'[Date] ),
'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
The calculation retains report selections but accumulates values through the current date.
Step 6: Set the item order
Arrange the calculation items in this sequence:
- Value
- % of Category Total
- Running Total
Use the Calculation items context menu or Properties pane to move items up or down.
Step 7: Test Value and Percentage in a Matrix
- Add a Matrix visual.
- Place
DimProduct[Category]in Rows. - Place
Reusable Calculations[Calculation]in Columns. - Place
[Total Sales]and[Total Quantity]in Values. - Temporarily filter the Calculation column to Value and % of Category Total.
| Category | Sales Value | Sales % | Quantity Value | Quantity % |
|---|---|---|---|---|
| Computing | 5,959 | 27.35% | 11 | 26.19% |
| Entertainment | 5,893 | 27.05% | 7 | 16.67% |
| Home | 4,771 | 21.90% | 9 | 21.43% |
| Mobile | 5,165 | 23.71% | 15 | 35.71% |
| Total | 21,788 | 100.00% | 42 | 100.00% |
Step 8: Test Running Total by date
- Create another Matrix visual.
- Place
Date[Date]in Rows. - Place
Reusable Calculations[Calculation]in Columns. - Place Total Sales and Total Quantity in Values.
- Filter the Calculation column to Value and Running Total.
- Filter Total Sales to is not blank so only transaction dates appear.
| Date | Daily Sales | Running Sales | Daily Quantity | Running Quantity |
|---|---|---|---|---|
| 3 Jan 2026 | 2,599 | 2,599 | 1 | 1 |
| 10 Jan 2026 | 796 | 5,978 | 4 | 12 |
| 17 Jan 2026 | 3,598 | 12,674 | 2 | 16 |
| 31 Jan 2026 | 552 | 21,788 | 8 | 42 |
The table shows selected checkpoints. Your Matrix should contain all 15 transaction dates.
Step 9: Validate with a calculation-item slicer
- Add
Reusable Calculations[Calculation]to a Slicer. - Enable Single select.
- Add Total Sales and Total Quantity to separate Card visuals.
- Select Value, then % of Category Total, then Running Total.
Step 10: Validate in DAX Query View
EVALUATE
SUMMARIZECOLUMNS (
DimProduct[Category],
'Reusable Calculations'[Calculation],
FILTER (
'Reusable Calculations',
'Reusable Calculations'[Calculation]
IN { "Value", "% of Category Total" }
),
"Total Sales", [Total Sales],
"Total Quantity", [Total Quantity]
)
ORDER BY
DimProduct[Category],
'Reusable Calculations'[Calculation]
The query should return two calculation rows for each of the four categories.
Optional protection for nonnumeric measures
If the model contains text measures such as Target Status, a percentage or running-total transformation is not meaningful. You can restrict a calculation item to selected numeric measures:
IF (
ISSELECTEDMEASURE (
[Total Sales],
[Total Quantity]
),
DIVIDE (
SELECTEDMEASURE (),
CALCULATE (
SELECTEDMEASURE (),
REMOVEFILTERS ( DimProduct[Category] )
)
),
SELECTEDMEASURE ()
)
This guarded version transforms Total Sales and Total Quantity but passes other measures through unchanged.
When should calculation groups be used?
Use a Calculation Group when the same transformation must be applied consistently to several explicit measures. Keep an ordinary measure when the business calculation is unique or needs a specific name that report authors should select directly.
Knowledge check
- What measure does SELECTEDMEASURE represent?
- Why are explicit measures required?
- Why does the percentage calculation remove Category?
- Why is a dynamic format string preferable to FORMAT?
- When should ISSELECTEDMEASURE protect a calculation item?
Troubleshooting
| Problem | What to check |
|---|---|
| The Calculation group button is unavailable. | Confirm you are editing a supported semantic model in Model view and are using a current Power BI Desktop version. |
| Raw numeric columns cannot be added to Values. | This is expected after Discourage implicit measures is enabled. Create and use explicit measures. |
| The percentage displays as a decimal. | Enable Dynamic format string for the percentage calculation item and enter "0.00%". |
| Running Total matches the daily value. | Use Date[Date] from the Date dimension and verify the active Date-to-Sales relationship. |
| A text measure returns an error. | Use ISSELECTEDMEASURE to restrict numeric transformations. |
Exercise complete
- The Reusable Calculations group contains three calculation items.
- Value preserves each measure's original result.
- Category percentages total 100% for Sales and Quantity.
- Running Sales reaches 21,788 on 31 January.
- Running Quantity reaches 42 on 31 January.
- The DAX query returns the expected category results.