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
ronaldbalza2023
Continued Contributor
Continued Contributor

COLOR FORMATTING - SWITCH STATEMENT

Hi everyone. I am using the switch statement for color formatting with this line of code. However, when it reaches to the same target amount, it doesn't excute the right formatting. What the code does it that if the actual meets or exceeds the target, the bg color will turn into green, if the actual meets atleast 90% of the target color will turn into yellow. the rest will turn into color red.

Now, the actual meets the exact target, the background supposedly turn into green but it doesn't. What did I missed? Thanks in advance.

% Productivity vs KPI Formmating = 
    SWITCH(
        TRUE(),
        [Productivity Percentage]>=[Productivity KPI],"#6aa84f", //GREEN
        [Productivity Percentage]>[Productivity KPI] * .90,"#feda03", //YELLOW 
        "#bf211e" //RED
    )



ronaldbalza2023_0-1662956475887.png

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @ronaldbalza2023 ,

from my perspective, the formatting measure works perfectly. I use exactly your definition, and this allows me to create the below table visual:
image.png
I created two very simple measures to represent the measures that are used inside the formatting measure:

Productivity Percentage = AVERAGE( 'Table'[Actual] ) 
Productivity KPI = AVERAGE( 'Table'[Target] )

and this one just to create a check inside the table:

Productivity Percentage 90 = AVERAGE( 'Table'[Target] ) * .9

 

Maybe, you can create a table showing the measures used inside the formatting measure. Be aware that this value (formatted by the UI) 55.0% does not equal the value 0.5501.

You need to format (adjust) the measure inside the DAX statement regarding the precision. 

 

Hopefully, this provides some ideas on how to tackle your challenge.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

1 REPLY 1
TomMartens
Super User
Super User

Hey @ronaldbalza2023 ,

from my perspective, the formatting measure works perfectly. I use exactly your definition, and this allows me to create the below table visual:
image.png
I created two very simple measures to represent the measures that are used inside the formatting measure:

Productivity Percentage = AVERAGE( 'Table'[Actual] ) 
Productivity KPI = AVERAGE( 'Table'[Target] )

and this one just to create a check inside the table:

Productivity Percentage 90 = AVERAGE( 'Table'[Target] ) * .9

 

Maybe, you can create a table showing the measures used inside the formatting measure. Be aware that this value (formatted by the UI) 55.0% does not equal the value 0.5501.

You need to format (adjust) the measure inside the DAX statement regarding the precision. 

 

Hopefully, this provides some ideas on how to tackle your challenge.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.