Forum Discussion
Conditional Formatting not working in Matrix Visual
- 11 months ago
A big thanks to everyone who has offered me help with this - thanks to your input I managed to find a way of solving my issue using the following DAX:
Percent of Row = DIVIDE( COUNT('Cases'[applicationvalidationdate]), CALCULATE( COUNT('Cases'[applicationvalidationdate]), REMOVEFILTERS('Cases'[Days to Validation Bins]) ) )
I then applied the following Conditiional Formatting criteria to the percentages (using numbers as advised).Which gives me the desrired result in my Matrix visual:
Hi ArchStanton ,
Your conditional formatting isn't working because it's evaluating the underlying raw count from your AppValCount measure, not the displayed percentage. The "Show values as % of Row Total" option is a visual-level setting that doesn't change the data the formatting rule actually sees. So, when your rule checks the value for April in the "0-1 Mth" column, it's testing the number 431 against your conditions (e.g., is 431 between 0.7 and 0.9?). Since it's not, no format is applied.
The solution is to create a new DAX measure that explicitly calculates the percentage value for each cell. You can then base your formatting rules on this new measure. First, create a measure to calculate the percent of the row total by using the following DAX code. Remember to replace 'Cases'[Mth] with the actual name of your month column.
AppVal Percent of Row =
VAR CurrentValue = [AppValCount]
VAR TotalForRow = CALCULATE(
[AppValCount],
ALLEXCEPT('Cases', 'Cases'[Mth])
)
RETURN
DIVIDE(CurrentValue, TotalForRow)
This DAX formula works by first capturing the value of the current cell (CurrentValue) and then calculating the total for the entire row (TotalForRow) by using ALLEXCEPT to remove all table filters except for the one on the month. It then safely divides the two to get the percentage. After creating this measure, select it and use the Measure tools tab to format it as a Percentage.
Now you can apply the conditional formatting correctly. Select your matrix, navigate to Format your visual > Cell elements, and turn on Background color. In the settings, base the rule on your new AppVal Percent of Row measure. Critically, you must set up your rules using Number as the type, not Percent. Your rules should be: If value is >= 0.9 Number, If value is >= 0.7 Number, etc. This will ensure the formatting evaluates the actual percentage value (e.g., 0.94) correctly.
To address your specific request to format only the "0-1 Mth" column, you'll need one final, specialized measure. This measure will check which column is being evaluated and only return the percentage for the target column, leaving the others blank so they don't get formatted. Be sure to replace 'YourTable'[AgeBandColumn] with the name of the column that contains your aging categories ("0-1 Mth", "1-2 Mths", etc.).
Format 0-1 Mth Column Only =
IF(
SELECTEDVALUE('YourTable'[AgeBandColumn]) = "0-1 Mth",
[AppVal Percent of Row]
)
Finally, go back into the conditional formatting settings one last time and change the field you are basing the rules on to this new Format 0-1 Mth Column Only measure. The rules themselves can stay the same. This will now apply your color logic exclusively to the "0-1 Mth" column.
Best regards,
Using your measure I get the following incorrect result:
AppVal Percent of Row =
VAR CurrentValue = [AppValCount]
VAR TotalforRow =
CALCULATE([AppValCount],
ALLEXCEPT('AppValTable',AppValTable[Mth ])
)
RETURN
DIVIDE(CurrentValue, TotalforRow)