** Conditional formatting of measures values in matrix based on given targets for given values (these values are rows in matrix)
The business users used Weighted Forecast Accuracy – WFA (A Percentage Measure) metric for various business divisions. They wanted to understand each division’s targets better to achieve 100% of the forecast.
We worked on the requirement with a matrix representation having measure values for some divisions(rows) with their targets and different months (as columns), and we must do conditional formatting (color) based on given targets for given divisions(rows) based on their individual targets. The data sets for targets and divisions that will be used to color the measures are as follows:
Divisions | Division Sort | Target 50 Percent | Target 100 Percent | Year |
Household Goods | 1 | 0.38 | 0.41 | 2022 |
Stationary | 2 | 0.54 | 0.56 | 2022 |
Foods | 3 | 0.50 | 0.52 | 2022 |
Drinks | 4 | 0.39 | 0.42 | 2022 |
Perfumes | 5 | 0.30 | 0.34 | 2022 |
Paints | 6 | 0.46 | 0.48 | 2022 |
Note: Format target fields as percentages
Conditions for Coloring:
If the Measure is Greater than 100%, then Green(#49ed24)
If the Measure is between 50% and 100%, then Yellow(#ede324)
If the Measure is below 50%, then Red(#eb684d)
In the PowerBI dashboard, we displayed the data of a measure in percentage form, where we included values with different divisions (from the given rows) on a per-month basis for the current year. Every division has specified targets; to check whether each division has achieved its targets in different months, we are making it in a colored pattern.
If Division=Household goods have achieved a 100% target of the forecast, then it would be green for them if they achieved 50% or more, yellow and less than 50%, then red.
The same goes for different divisions with different targets of 50%,100%, etc.
Solution:
We created a table with targets as per the given divisions (rows).
So, to achieve this, first, we must have the table with the given dataset. Once it is done, we create the measure as per the requirement that we want to see, giving the output as a color.
If a measure for Division=Daily Use has achieved a 100% target, or it can achieve it, or is more than the required target, then the color output will be green.
Else if it’s less than 100% and greater than 50%, then yellow; it selects red.
Note: We will need to format as per the current year that we have in our table.
Then we created a measure that can be used to format in measure with conditions; here is the stepwise approach:
1st Step: Create a Measure with the below code, which needs to be modified as per your table/column name:
Once this is created, be sure to have it as datatype Text, else it won’t appear when we choose the conditional formatting field by value option.
2nd Step: Right-click on the Values tab of the matrix and choose the Conditional Formatting option.
3rd Step: Choose the Field by value option from the drop-down and choose the above “create measure”.
RESULT
Example for Matrix before conditional formatting
Division | Target 100% | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep |
Household Goods | 41% | 30% | 33% | 14% | 8% | 37% | 47% | 0% | 0% | 33% |
Stationery | 56% | 57% | 19% | 27% | 17% | 62% | 0% | 53% | 63% | 58% |
Foods | 52% | 30% | 41% | 18% | 8% | 42% | 29% | 9% | 0% | 28% |
Drinks | 42% | 39% | 1% | 1% | 0% | 27% | 0% | 31% | 32% | 31% |
Perfumes | 34% | 32% | 19% | 17% | 37% | 36% | 19% | 0% | 0% | 22% |
Paints | 48% | 13% | 48% | 22% | 15% | 41% | 0% | 46% | 39% | 41% |
Example for Matrix after conditional formatting