## Calculation Groups

Analysis Services tabular models can have hundreds of base DAX measures, duplications of code, and syntax. However, with the new world of DAX Calculation groups we can re-use calculations and apply them to virtually any measure.

Within analysis services, DAX Calculation Groups give the user the ability to apply multi-use calculations to measures. This feature is available on Analysis Services in SQL Server 2019 2.3 and should be available in the SQL Server 2019 release. Currently, calculation groups can only be created with the Tabular Editor UI.

The first, and most prominent example of this is time intelligence and the application of MTD (Month to Date), YTD (Year to Date), and QTD (Quarter to Date) calculations. By reducing the number of measures, with calculation groups we can present a clearer user interface to the users.

Below are two images that show the calculation group hierarchy. The hierarchy is used to call a calculation on a measure.

The calculation group is called calculation group, the attribute is called time, and the item is called MTD.

The calculation items use the new ‘SelectedMeasure’ function. When called ‘SelectedMeasure’ will replace the measure that you have selected for calculation.

CALCULATE(SELECTEDMEASURE(), DATESMTD(DimDate[Date])) CALCULATE(SELECTEDMEASURE(), DATESYTD(DimDate[Date])) CALCULATE(SELECTEDMEASURE(), DATESQTD(DimDate[Date]))

The script below calculates the measure ‘InternetTotalSales’ upon the calculation items; ‘Current’, ‘QTD’, ‘YTD’ etc.

EVALUATE CALCULATETABLE ( SUMMARIZECOLUMNS ( DimDate[CalendarYear], DimDate[EnglishMonthName], "Current", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "Current" ), "QTD", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "QTD" ), "YTD", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "YTD" ), "PY", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "PY" ), "PY QTD", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "PY QTD" ), "PY YTD", CALCULATE ( [InternetTotalSales], 'CalculationGroup'[Time] = "PY YTD" ) ), DimDate[CalendarYear] IN { 2012, 2013 }

And, when we run this script we get the following table:

Looking forward, we should see this eventually in PowerBI, SQL Server Data tools, and Azure Analysis Services. So, watch this space.

Throughout this year, you will see more blogs and guides from me on this topic as it unfolds.

## Add comment

Cancel reply to comment