Calculation groups are a robust modeling feature in Power BI that reduces redundant measures created by grouping standard measure expressions as calculation items. The calculation group is like a table with DAX expressions for each of the calculation items.

Let us consider a scenario where you need time-related calculations like YTD, MTD, QTD for sales amount, sales quantity, profit measures. Here, in general, we will be creating time calculations of each measure resulting in 9 calculations. To avoid the redundant calculation, we can create a calculation group for time-related calculations and use it with any base measure.

Calculation groups are supported in tabular models at the 1500 and higher compatibility level. Calculation groups work with explicit DAX measures. ‘DiscourageImplicitMeasures’ model property should be set to ‘true’ to create calculation groups. As of the July 2020 release, we can access external tools like Tabular editor, DAX studio, ALM toolkit, etc. from the Power BI Desktop. You need to install these external tools individually. These external tools are automatically connected to the Analysis Services engine, providing a seamless experience for users.

After the initial setup, the Power BI Desktop will look like below with external tools ribbon. For creating calculation groups, we will be using Tabular editor.

Leveraging calculation groups in Power BI

1. From the External Tools ribbon, launch Tabular editor from Power BI Desktop and right-click on Tables and select Create New -> Calculation Group.

Leveraging calculation groups in Power BI
Calculation Group Option

Initially, you will have one unique table created for the calculation group. Provide a suitable name for calculation group and create individual calculation items for each time calculation like below:

  • PY YTD – CALCULATE(SELECTEDMEASURE(),SAMEPERIODLASTYEAR(‘Date table'[Date]),’Timecalgroup'[Timecal]= “YTD”)
  • YOY % – DIVIDE(CALCULATE(SELECTEDMEASURE(),’Timecalgroup'[Timecal] =”YOY”),CALCULATE(SELECTEDMEASURE(),’Timecalgroup'[Timecal] =”PY”))
Leveraging calculation groups in Power BI
Time Calculation Group

Click on the ‘Save’ icon, which will save the changes to the connected database and the Power BI Desktop. You will get a warning to manually refresh whenever you modify the calculation group, like adding or deleting a calculation item.

Leveraging calculation groups in Power BI
Manual Refresh

On refreshing, the calculation group will be available for usage. You can drag and drop in a matrix or slicer with a base measure. The below matrix contains the sales amount measure with our ‘Timecalgroup’ calculation group.

Leveraging calculation groups in Power BI
Calculation Group in Matrix

Here the YOY% measure should have value in percentage. We need to override the base format string and use %. In each calculation item, we can update the format string both statically and dynamically using DAX’s format function. Below we have provided the format string as “0.00%; -0.00%;0.00%” to contain the format for positive, negative, and zero values.

Leveraging calculation groups in Power BI
Format String

This is useful during currency calculations where different formats can be provided for your currency using the ‘format string expression.’ When sorting the calculation items, we can assign a value in ‘ordinal’ property that is sequential. The calculation item with an ordinal property of 1 will appear first, 2 next, and so on. If you see our YOY%, we assigned 7 as the ordinal value and it appears last in the report.

Leveraging calculation groups in Power BI
Calculation Group with a Format String

In the calculation group, using the precedence’ property, we can specify the order of evaluation when there is more than one calculation group.  Greater value in ‘precedence’ means it is of more precedence and evaluated first.

A use case is to see daily average sales and YTD daily average sales. Create a new calculation group for average called ‘Averagecalgroup’ and add a daily average calculation item.

Daily average =DIVIDE(SELECTEDMEASURE(), COUNTROWS(‘Date table'[Date]))

CALCULATE(SELECTEDMEASURE(), ‘Timecalgroup'[Timecal]= “YTD”, ‘Averagecalgroup'[Averagecal] = “Daily average”)

‘Timecalgroup’ calculation group should have higher precedence than ‘Averagecalgroup’ since we need YTD daily average.  YTD should be applied to both numerator and denominator. We will set precedence 20 for ‘Timecalgroup’ and 10 for ‘Averagecalgroup’ to avoid miscalculations.

We can create calculation groups for base measures to use in a slicer or filter for measure selections. Create a calculation group called ‘Measurecalgroup’ and create individual calculation items for each measure. The DAX expression is the base measure itself.

Leveraging calculation groups in Power BI
Measure Calculation Group

You can see the calculation groups for time calculation and also for the base measure in action below.

Leveraging calculation groups in Power BI
Calculation Group

Learn more about Microsoft Power BI services offerings from Visual BI solutions here.

Corporate HQ:
5920 Windhaven Pkwy, Plano, TX 75093

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

Copyright © Visual BI Solutions Inc.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This!

Share this with your friends and colleagues!