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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NLewis
Frequent Visitor

Dax Conditional Formatting

I'm struggling! Can anyone give me the actual Dax formula for the conditons on the bottom screenshot? I'm trying to create a pie chart like the top screenshot (that can give me % totals). I'm lost. I tried

 
BackgroundColor =
SWITCH (
TRUE (),
IF('Measures Table'[TerminalWeeklyQuality] > 0.979 <= 1, "GREEN"),
IF('Measures Table'[TerminalWeeklyQuality] > 0.9599 < 0.979, "YELLOW"),
IF('Measures Table'[TerminalWeeklyQuality] >= 0 < 0.9599, "RED"))

 

 

NLewis_1-1644881188253.png

NLewis_2-1644881291956.png

 

 

1 ACCEPTED SOLUTION
TheoC
Super User
Super User

Hi @NLewis 

 

I think you're close. Try adjusting to the below:

 

BackgroundColor =

VAR _1 = [TerminalWeeklyQuality]

RETURN


SWITCH
 (
TRUE (),
_1 < 0.9599, "RED" ,
_1 0.979"YELLOW" ,
"GREEN" )

The logic with the TRUE() removes the need for an IF statement given, and the between parameters (i.e. > and < ) don't need to be applied because everything under 0.9599 can be red, followed by anything under 0.979 being yellow, and everything else green.  The logic in the SWITCH ( TRUE () ... tests everything in order from start to end.

So the order is:

1. If below 0.9599 then RED else

2. If below 0.979 then YELLOW otherwise

3. Just make it GREEN and be done with it!

Hope this helps!

Theo

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

View solution in original post

5 REPLIES 5
TheoC
Super User
Super User

Hi @NLewis 

 

I think you're close. Try adjusting to the below:

 

BackgroundColor =

VAR _1 = [TerminalWeeklyQuality]

RETURN


SWITCH
 (
TRUE (),
_1 < 0.9599, "RED" ,
_1 0.979"YELLOW" ,
"GREEN" )

The logic with the TRUE() removes the need for an IF statement given, and the between parameters (i.e. > and < ) don't need to be applied because everything under 0.9599 can be red, followed by anything under 0.979 being yellow, and everything else green.  The logic in the SWITCH ( TRUE () ... tests everything in order from start to end.

So the order is:

1. If below 0.9599 then RED else

2. If below 0.979 then YELLOW otherwise

3. Just make it GREEN and be done with it!

Hope this helps!

Theo

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

NLewis
Frequent Visitor

1 more question...how do I turn this into a pie chart using the formated % values

NLewis
Frequent Visitor

Thank you @TheoC...I made that way more complicated than it was😀

NLewis
Frequent Visitor

It's not working. I says that I need to use VALUE or FORMAT...but when I tried SELECTVALUE(cant use VALUES...all the %'s are not unique)...but I'm getting an error line under my VAR calculation...my variable is a measure...should that matter?

@NLewis is the [TerminalWeeklyQuality] a Measure or a column?   I assumed measure as it was in a measure table? 

 

Otherwise, just change it to the following:

 

BackgroundColor =

SWITCH (
TRUE (),
Table[TerminalWeeklyQuality] < 0.9599, "RED" ,
Table[TerminalWeeklyQuality] 0.979"YELLOW" ,
"GREEN" )

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.