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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DMB1
Frequent Visitor

Conditional Formatting Table Background Colour - (IF Text & Value then color)

I have a table like the following.  I want to set a conditional format background color based on the name and numerical value.  Multiple rules based on the name in the first column and value in the second.

 

For Example:

If Audit Manager = "Fred"  & Audits = 20  then  green

If Audit Manager = "Fred" & Audits <20 then yellow

If Audit Manager = Fred & Audits >20 then Red

If Audit Manager = George & Audits =3 then Green

If Audits Manager = George & Audits ❤️ then yellow

If Audit Manager = George & Audits >3 then Red

 

Audit ManagerAudits
Fred20
George1
Ginny80
Ron2
Percy20

 

I think I need a measure to refer to when applying the conditional formating on the table but not entirely sure of code that is needed.

 

It looks like it should be easy,  but please note a value of 3 for one name might be red but for another name it might be green.  I need separate rules based on the names and numbers.

1 REPLY 1
edhans
Super User
Super User

Hi @DMB1 - this will work. Note that the yellow isn't showing up great on my image, but George is indeed yellow as i it is 1. Fred is also green, which is kind of dark. 

Tracked Manager = 
VAR varManagerName = MAX('Table'[Audit Manager])
VAR varAudits = MAX('Table'[Audits])
VAR Result = 
    SWITCH(
        TRUE(),
        AND(varManagerName = "Fred", varAudits = 20), "green",
        AND(varManagerName = "Fred", varAudits < 20), "yellow",
        AND(varManagerName = "Fred", varAudits > 20), "red",
        AND(varManagerName = "George", varAudits = 3), "green",
        AND(varManagerName = "George", varAudits < 3), "yellow",
        AND(varManagerName = "George", varAudits > 3), "red"
    )
RETURN
    Result

edhans_0-1610047520551.png

 

Note you can replace red/green/yellow with hex colors, so the following works. You must remember the # sign for hex numbers:

Tracked Manager = 
VAR varManagerName = MAX('Table'[Audit Manager])
VAR varAudits = MAX('Table'[Audits])
VAR Result = 
    SWITCH(
        TRUE(),
        AND(varManagerName = "Fred", varAudits = 20), "green",
        AND(varManagerName = "Fred", varAudits < 20), "#FFD300",
        AND(varManagerName = "Fred", varAudits > 20), "red",
        AND(varManagerName = "George", varAudits = 3), "green",
        AND(varManagerName = "George", varAudits < 3), "#FFD300",
        AND(varManagerName = "George", varAudits > 3), "red"
    )
RETURN
    Result

That gives you a darker yellow for example. 

The conditional format for the font color is this, where "Tracked Manager" is the measure name I chose.

edhans_1-1610047664335.png

 

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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