March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
This multi-part tutorial blog is geared to help BI Analysts create versatile Scorecards with KPIs as well as to facilitate the business reporting transition from Excel, SSRS or other apps to Power BI Desktop.
In this initial installment, I will illustrate how to include more than one aggregation and custom formatting in the Power BI Desktop Matrix. All tutorial steps below require acquaintance with how Power BI Desktop works as well as basic to advanced DAX skills.
Let’s start by creating the initial Power BI Desktop matrix based on sample monthly KPI data that requires different YTD aggregations and formatting for the Targets and the Actuals.
PerformanceYTD table
Create the initial Power BI Desktop Matrix:
By default, the Power BI Desktop Matrix has the same aggregation and formatting applied to all KPI’s Targets and Actuals. I am going to add customization using DAX in the next two sections to meet the Performance YTD matrix requirements specified in the Aggregation and Formatting fields.
Add Custom Aggregation for the Targets and Actuals
Referring to the PerformanceYTD table above: Target and Actual values for the Avg Orders per Customer KPI should be averaged, Target and Actual values for the Total Orders and Total Customers KPIs should be summed, and the rest should always show the latest CalendarYearMonth's value. This can be accomplished with the following steps:
TargetWithAggregations = IF(MIN('Measures YTD'[Aggregation]) = "Avg", AVERAGE('Measures YTD'[Target]), IF(MIN('Measures YTD'[Aggregation]) = "Last", CALCULATE (SUM ('Measures YTD'[Target] ), LASTNONBLANK ( 'Measures YTD'[CalendarYearMonth], CALCULATE (SUM('Measures YTD'[Target]) ) ) ) , IF(MIN('Measures YTD'[Aggregation]) = "Sum", SUM('Measures YTD'[Target]), 0)))
ActualWithAggregations = IF(MIN('Measures YTD'[Aggregation]) = "Avg", AVERAGE('Measures YTD'[Actual]), IF(MIN('Measures YTD'[Aggregation]) = "Last", CALCULATE (SUM ('Measures YTD'[Actual] ), LASTNONBLANK ( 'Measures YTD'[CalendarYearMonth], CALCULATE (SUM('Measures YTD'[Actual]) ) ) ) , IF(MIN('Measures YTD'[Aggregation]) = "Sum", SUM('Measures YTD'[Actual]), 0)))
Next, we are going to add custom formatting to the Target and Actual values.
Adding Custom Formatting for the Targets and Actuals
When measures of different nature are tracked in the same Matrix, custom formatting may be necessary. In our case, we need four different custom formatting types ranging from Percent to USD Currency. This can be accomplished with the following steps, similar to the previous section:
TargetWithAggregationsAndFormatting = IF(MIN('Measures YTD'[Formatting]) = "Number", FORMAT([TargetWithAggregations],"#,##0;(#,##0)"), IF(MIN('Measures YTD'[Formatting]) = "Number with 1 Decimal", FORMAT([TargetWithAggregations],"#,##0.0;(#,##0.0)"), IF(MIN('Measures YTD'[Formatting]) = "Percent", FORMAT([TargetWithAggregations], "0.0%"), IF(MIN('Measures YTD'[Formatting]) = "USD Currency", FORMAT([TargetWithAggregations],"$#,##0;($#,##0)"),0))))
ActualWithAggregationsAndFormatting = IF(MIN('Measures YTD'[Formatting]) = "Number", FORMAT([ActualWithAggregations],"#,##0;(#,##0)"), IF(MIN('Measures YTD'[Formatting]) = "Number with 1 Decimal", FORMAT([ActualWithAggregations],"#,##0.0;(#,##0.0)"), IF(MIN('Measures YTD'[Formatting]) = "Percent", FORMAT([ActualWithAggregations], "0.0%"), IF(MIN('Measures YTD'[Formatting]) = "USD Currency", FORMAT([ActualWithAggregations],"$#,##0;($#,##0)"),0))))
There are predefined Numeric Formats, for example, FORMAT([ActualWithAggregations], "Currency"). If using predefined Numeric formats, please keep in mind that the decimal places are preset.
To validate that the aggregation and formatting for the Targets and Actuals are as per the requirements set in the PerformanceYTD table, add the CalendarYearMonth field to the Matrix Rows, and the Aggregations and Formatting fields in the Matrix values. Then, click on the top left corner to select the conjoined arrows to drill-down to the CalendarYearMonth level.
Lastly, I am going to rename TargetWithAggregationsAndFormatting and ActualWithAggregationsAndFormatting calculated measures to Target and Actual in the Values section of the Power BI Desktop Matrix:
I hope you enjoyed this tutorial for custom aggregations and formatting for the Power BI Desktop Matrix. Stay tuned for the second blog installment, Power BI Desktop: Custom Aggregations, Formatting and Performance Indicators (Part 2), in which I will give step by step instructions on how to add color performance indicators next to the Actual value based on the associated Target value.
In part 2 of this post I will give a step by step tutorial on how to add color performance indicators next to the actual values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.