cancel
Showing results for 
Search instead for 
Did you mean: 
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
Super User
Super User

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
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors