Saturday, March 21, 2026

How to create and use Calculation Groups in Power BI

How to define and use Calculation Groups in Power BI
A Calculation Group is a feature in Power BI that lets you define reusable logic once and apply it across multiple measures. 
Instead of writing separate DAX formulas for each measure (like [Sales] and [Orders]), we can create calculation items (such as Current Month, Previous Month, Month‑over‑Month Growth) that automatically work with any base measure.
Scenario:
Suppose we have 2 measures as [Sales] and [Orders] as base measures in our Data Model. For which we want to calculate the values for Previous Month and Monthly Growth by using the Calculation Groups, defined in Power BI Model as discussed below.

Data Model:

Relationships:

Base Measures:
Sales = Sum(fct_Orders_Sample[Gross_Sales])
Orders = COUNT(fct_Orders_Sample[Order_ID])

Now, we can define Calculation group with below Calculation Items to calculate the values for Previous Month and Monthly Growth.

The Calculation Groups can be defined from Model view of the Power BI:


MoM_Growth_Group: It is the Calculation Group Name
MoM_Growth_Field: It is the Column name of Calculation Group. This Column will be used in the Visuals to display the Calculation Items (Measures).

In the Table view, it will display as per below:



Here, Index is the Ordinal value. 
The default ordinal value for a calculation item/measure is '-1', and its Index starts from 0.

Current Month Value =
VAR _Enable_Flag = 1
VAR _Result =SELECTEDMEASURE()
RETURN
IF(_Enable_Flag, _Result)

Prev Month Value =
VAR _Enable_Flag = 1
VAR _Result =
CALCULATE(SELECTEDMEASURE(),
        DATEADD( Dim_Calendar[DimDate], -1, MONTH)
        )
RETURN
IF(_Enable_Flag, _Result)


% MoM Growth =
VAR _Enable_Flag = 1
VAR _CM =
    SELECTEDMEASURE()
VAR _PM =
    CALCULATE(
        SELECTEDMEASURE(),
        DATEADD(Dim_Calendar[DimDate], -1, MONTH)
    )
VAR _Growth = DIVIDE((_CM - _PM), _PM)
VAR _Msr_Format = FORMAT(_Growth, "00.0%;00.0%")
VAR _Result =
    SWITCH(
        TRUE(),
        ISBLANK(_Growth), _Msr_Format & " " & UNICHAR(9899), --Grey Circle
        ISBLANK(_CM), _Msr_Format & " " & UNICHAR(9899),     --Grey Circle
        _Growth = 1, _Msr_Format & " " & UNICHAR(9899),      --Grey Circle
        _Growth < 0, _Msr_Format & " " & UNICHAR(128308),    --Red Circle
        _Growth > 0, _Msr_Format & " " & UNICHAR(128994)     --Green Circle
    )
RETURN
IF(AND(_Enable_Flag, NOT ISBLANK(_Growth)), _Result)

Notes:
We can set _Enable_Flag = 0 to a disable or not to display a Calculation Item from Group.
The Dynamic format string "#.##" used for the Calculation Items [Current Month Value] and the [Previous Month Value].
The Dynamic format string "00.0%;00.0%" used for the Calculation Item [% MoM Growth]

The output of the Calculation Group and its Items is as per below. 

New Card Visual for Orders:
For the new Card Visual, we need to use the MoM_Growth_Field in the Categories section.



New Card Visual for Sales:


Matrix Visual for both Orders and Sales Measures:
For the Matrix Visual, we need to use the MoM_Growth_Field in the Columns section.



Note:
Currently, the Calculation groups are only fully supported in visuals that can pivot measures dynamically, like the Matrix (and Pivot‑style visuals). For Table visual they will not work.

--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog