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.

Learning goal: replace duplicated measure patterns with calculation items that reference the current measure through SELECTEDMEASURE().
Calculation GroupSELECTEDMEASUREDynamic formatCalculation reuse

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 Group reuse Total Sales and Total Quantity enter the same Calculation Group, which returns Value, Percentage of Category Total, or Running Total. Total Sales21,788 Total Quantity42 Reusable CalculationsSELECTEDMEASURE()Value% of Category TotalRunning Total MatrixTwo measuresThree reusablecalculations One calculation pattern can transform many explicit measures.

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] )
Control totals: Total Sales = 21,788 and Total Quantity = 42.

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.

Your existing explicit measures continue to work. Use measures such as Total Sales and Total Quantity in visuals instead of raw numeric columns.

Step 1: Create the Calculation Group

  1. Open Model view.
  2. On the ribbon, select Calculation group.
  3. If prompted to enable Discourage implicit measures, select Yes.
  4. Rename the new Calculation Group to Reusable Calculations.
  5. Rename its calculation-group column to Calculation.

Power BI creates the first calculation item automatically.

Step 2: Create the Value calculation item

  1. Rename the first calculation item to Value.
  2. 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

  1. Right-click the Calculation items section and select New calculation item.
  2. Name it % of Category Total.
  3. 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

  1. Select the % of Category Total calculation item.
  2. In the Properties pane, enable Dynamic format string.
  3. Enter:
"0.00%"

The result remains numeric but is displayed as a percentage.

Step 5: Create Running Total

  1. Create another calculation item named Running Total.
  2. 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:

  1. Value
  2. % of Category Total
  3. 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

  1. Add a Matrix visual.
  2. Place DimProduct[Category] in Rows.
  3. Place Reusable Calculations[Calculation] in Columns.
  4. Place [Total Sales] and [Total Quantity] in Values.
  5. Temporarily filter the Calculation column to Value and % of Category Total.
CategorySales ValueSales %Quantity ValueQuantity %
Computing5,95927.35%1126.19%
Entertainment5,89327.05%716.67%
Home4,77121.90%921.43%
Mobile5,16523.71%1535.71%
Total21,788100.00%42100.00%

Step 8: Test Running Total by date

  1. Create another Matrix visual.
  2. Place Date[Date] in Rows.
  3. Place Reusable Calculations[Calculation] in Columns.
  4. Place Total Sales and Total Quantity in Values.
  5. Filter the Calculation column to Value and Running Total.
  6. Filter Total Sales to is not blank so only transaction dates appear.
DateDaily SalesRunning SalesDaily QuantityRunning Quantity
3 Jan 20262,5992,59911
10 Jan 20267965,978412
17 Jan 20263,59812,674216
31 Jan 202655221,788842

The table shows selected checkpoints. Your Matrix should contain all 15 transaction dates.

Step 9: Validate with a calculation-item slicer

  1. Add Reusable Calculations[Calculation] to a Slicer.
  2. Enable Single select.
  3. Add Total Sales and Total Quantity to separate Card visuals.
  4. Select Value, then % of Category Total, then Running Total.
Scope matters: on a grand-total Card with no Category or Date row context, Value, Category Percentage, and final Running Total can all appear as the overall result. Calculation differences are easiest to understand in a Matrix containing Category or Date rows.

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

  1. What measure does SELECTEDMEASURE represent?
  2. Why are explicit measures required?
  3. Why does the percentage calculation remove Category?
  4. Why is a dynamic format string preferable to FORMAT?
  5. When should ISSELECTEDMEASURE protect a calculation item?

Troubleshooting

ProblemWhat 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

You have defined calculation logic once and reused it across multiple explicit measures. This reduces duplicate DAX, improves consistency, and makes future semantic-model maintenance easier.
Completion checklist
  • 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.

References