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
GeekyT
Helper II
Helper II

Unable to Add Conditional Formatting to a Measure

I have created a measure to tell me whether a task is overdue based on it's due date. This is the DAX I used:

 

State = IF(MIN('wkaw'[Due Date])<TODAY(),"1",
(IF(MIN('wkaw'[Due Date])>=TODAY(),"2",
(IF(MIN('wkaw'[Due Date])>=TODAY()+7,"3"
)))))
 
Where 1 is overdue, 2 is due this week and 3 is due after more than a week.
 
It works perfectly well without any errors.
 
However I'd like the 'State' to change colour dependant on it's value, so I tried to set up
conditional formatting but when I try to select State from the 'Based on Field' list to format
it won't let me select it. For every other field, when you hover the pointer over the name, it goes
grey to indicate it can be selected but not my measure.
Has anyone else come across this? I can't find any information online to suggest there are particular
conditions a field must meet before you can apply conditional formatting.
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@GeekyT , Not very clear, Create a color measure and use that in conditional formatting with "Field value"

State = Switch( true(),
MIN('wkaw'[Due Date])<TODAY(),"green",
MIN('wkaw'[Due Date])>=TODAY(),"yellow",
MIN('wkaw'[Due Date])>=TODAY()+7,"red"
)

 

refer https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @GeekyT ,

 

The condittional formatting based on field value means that you have to set the colour that you need on your measure in this case yuou need to redo your measure to one of the formulas below.

 

One thing that I believe is also best is instead of havinf nested IF is to use SWITCH function.

 

State =
SWITCH (
    TRUE (),
    MIN ( 'wkaw'[Due Date] ) < TODAY (), "Red",
    MIN ( 'wkaw'[Due Date] ) >= TODAY (), "Green",
    MIN ( 'wkaw'[Due Date] )
        >= TODAY () + 7, "Blue"
)



State =
SWITCH (
    TRUE (),
    MIN ( 'wkaw'[Due Date] ) < TODAY (), "#00000",
    MIN ( 'wkaw'[Due Date] ) >= TODAY (), "#123456",
    MIN ( 'wkaw'[Due Date] )
        >= TODAY () + 7, "#963852"
)

 

The first measure you can write the colour you need directly, on the second one I'm using the HEX code so you can change the 6 digits in each one for the custom colours you want.

 

Then you canuse the based in value formula for the conditional formatting.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



amitchandak
Super User
Super User

@GeekyT , Not very clear, Create a color measure and use that in conditional formatting with "Field value"

State = Switch( true(),
MIN('wkaw'[Due Date])<TODAY(),"green",
MIN('wkaw'[Due Date])>=TODAY(),"yellow",
MIN('wkaw'[Due Date])>=TODAY()+7,"red"
)

 

refer https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

@amitchandak Fantastic! I was unaware of colour measures. Works perfectly.

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.