Power BI Matrix: keep conditional formatting (background colour) when the matrix is expanded (May 2025 Desktop)

Summary

The issue at hand is related to Power BI Matrix visuals, where conditional formatting applied to the background color of cells disappears when the matrix is expanded. This problem occurs when using a two-level matrix with fields in the Rows section and a measure in the Values section. The goal is to consistently highlight the single highest value using conditional formatting.

Root Cause

The root cause of this issue lies in the way Power BI handles conditional formatting when the matrix is expanded. The main reasons are:

  • Context transition: When the matrix is expanded, the context of the calculation changes, affecting the conditional formatting.
  • Filter removal: The expansion of the matrix removes filters applied to the lower-level fields, which can impact the calculation of the measure used for conditional formatting.
  • DAX calculation: The DAX formula used for the measure and conditional formatting may not be robust enough to handle the changes in context and filters.

Why This Happens in Real Systems

This issue occurs in real systems due to:

  • Complex data models: Real-world data models often involve complex relationships and hierarchies, making it challenging to maintain consistent conditional formatting.
  • Dynamic user interactions: Users may interact with the matrix in various ways, such as expanding or collapsing rows, which can affect the conditional formatting.
  • Measure calculations: The calculations used for measures and conditional formatting may not be designed to handle the dynamic nature of user interactions.

Real-World Impact

The impact of this issue is significant, as it affects the ability to:

  • Highlight important information: The disappearance of conditional formatting makes it difficult to highlight important information, such as the highest value in a matrix.
  • Analyze data: The inconsistent application of conditional formatting can lead to incorrect analysis and insights.
  • Create effective reports: The issue can limit the ability to create effective reports that provide clear and consistent visualizations of the data.

Example or Code

Δ – Color (MAX only) = 
VAR _val = [$ Δ]
VAR _base = ALLSELECTED ( 'Site Profile' )
VAR _sites = CALCULATETABLE ( VALUES ( 'Site Profile'[Site] ), _base, REMOVEFILTERS ( 'Site Profile'[LHN] ), REMOVEFILTERS ( 'Site Profile'[Site] ))
VAR _lhns = CALCULATETABLE ( VALUES ( 'Site Profile'[LHN] ), _base, REMOVEFILTERS ( 'Site Profile'[LHN] ), REMOVEFILTERS ( 'Site Profile'[Site] ))
VAR _maxv = MAXX ( _lhns, CALCULATE ( [$ Δ], REMOVEFILTERS ( 'Site Profile'[Site] ), TREATAS ( _sites, 'Site Profile'[Site] )))
RETURN 
    IF ( ISBLANK ( _val ) || ISBLANK ( _maxv ), BLANK (), 
    IF ( _val = _maxv, "#E53935", BLANK () ))

How Senior Engineers Fix It

Senior engineers fix this issue by:

  • Revising the DAX formula: Updating the DAX formula to handle the changes in context and filters when the matrix is expanded.
  • Using more robust calculations: Implementing more robust calculations that can handle the dynamic nature of user interactions.
  • Testing and validating: Thoroughly testing and validating the conditional formatting to ensure it works consistently across different scenarios.

Why Juniors Miss It

Junior engineers may miss this issue due to:

  • Lack of experience: Limited experience with complex data models and Power BI visuals.
  • Insufficient understanding of DAX: Inadequate understanding of DAX calculations and how they interact with conditional formatting.
  • Inadequate testing: Failure to thoroughly test and validate the conditional formatting across different scenarios.

Leave a Comment