Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MSvante
New Member

Conditional formatting by a measure.

Hi Guys, I'm having issues with conditional formatting. I have made the following measure, which calculates a 30-day average on some values. The rows in the dataset for the values are coming in each hour, therefore I times it by 24 to get the average for a day. The average works as a threshold for the values. I have a matrix that shows the value for each day in the dataset. I need to be able to make the background of the cells in the matrix, red if the value is above the 50% threshold, orange if the value is above 30% or grey if the value is on a weekend. If the value exceeds the thresholds on a weekend, it still needs to turn into orange/red. Therefore I have made this measure.

Threshold =
VAR moving_avg = (CALCULATE(AVERAGEX(KPI_Dashboard_test, KPI_Dashboard_test[Values]),DATESINPERIOD('Calendar'[DimDate_Date],LASTDATE('Calendar'[DimDate_Date]),-30,DAY))) * 24
VAR 30percent = moving_avg * 1.3
VAR 50percent  = moving_avg * 1.5

RETURN

MAXX(KPI_Dashboard_test,
    IF(KPI_Dashboard_test[Values] > 50percent,1,
    IF(KPI_Dashboard_test[Values] > 30percent,2,
    IF(KPI_Dashboard_test[Weekend] = 1,3,4))))'

The Conditional formatting is then set up as

IF is 1, then red
 IF is 2, the orange
 IF is 3, then grey

I haven't put anything in for 4, as that should just be the default colour of the matrix. I have isolated the issue down to the use of MAXX, as the data comes in hourly, but are shown per day, thus MAXX only takes the value from the hour with the highest. For the life of me, I can't figure out how to calculate it properly. If I replace MAXX with SUMX within the IF-statements I get the error that it cannot work with types of boolean. I can't calculate the variables as individual columns, as that creates circular dependecies. Basically, I feel lost for options

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

By the looks of it, you don't need the MAXX at all. Just leave the result to the IF expressions but change the column expressions to an aggregation ( for example SUM(KPI_Dashborpard_test [Values]) instead of the bare KPI_Dashboard_test[Values] ), and if you don't need the "4", you might aswell just leave it out of the expression (it will return BLANK () by default)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors