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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Gopiraju404
Frequent Visitor

How to apply conditional formatting in the table in Power BI based on three-color rule comparing .

Hi everyone,

I'm working on table in the Power BI and need help applying conditional formatting to a table using a 3-color logic.

Here’s what I’m trying to achieve:

I have a table with three columns:

  • Actual (Previous Year)

  • Target (Current Year)

  • Current YTD

I want to apply conditional formatting based on this logic:

🟩 Green – Meet target / goal
🟨 Yellow – Less than goal and greater than previous year
🟥 Red –  Less than goal and less than previous year

 

This is sample data.

Gopiraju404_0-1749192326147.png

 

Thanks and regards.

1 ACCEPTED SOLUTION

This is sample data.

Gopiraju404_0-1749213502211.png

 

Please help

Thank you.

View solution in original post

8 REPLIES 8
v-ssriganesh
Community Support
Community Support

Hello @Gopiraju404,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I have reproduced your scenario and successfully applied the conditional formatting to the table in Power BI using the 3-color logic you described:

  • Green: Current YTD meets or exceeds Target (Current Year).
  • Yellow: Current YTD is less than Target (Current Year) but greater than Actual (Previous Year).
  • Red: Current YTD is less than both Target (Current Year) and Actual (Previous Year).

I was able to achieve the expected output as per your requirements. For your reference, I’ve attached the .pbix file below, which includes the table with conditional formatting applied. You can download and review it to see the implementation.

Output:

vssriganesh_0-1749212162600.png

 

I noticed that your data contains mixed data types, such as percentages (e.g: 75%), text (e.g: "NA", "Track"), and large numbers with suffixes (e.g: 5.5M, 3.5B). To ensure the conditional formatting works correctly, I recommend cleansing the data in Power Query Editor before applying the logic.

Thank you, @Bibiano_Geraldo & @pankajnamekar25 for sharing your valuable insights.


If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Thank you for your response. your logic is applying on values but I also want colors  in  Q1 based on the text values in Target and Actual of achivevement.

This is my exact  sample data.

Gopiraju404_0-1749233953898.png

please help

Thanks and regards.

pankajnamekar25
Memorable Member
Memorable Member

Hello @Gopiraju404 

 

Try this measure

 

Color Logic =

VAR Actual = SELECTEDVALUE('Table'[Actual(Previous Year)])

VAR Target = SELECTEDVALUE('Table'[Target(Current Year)])

VAR Current = SELECTEDVALUE('Table'[Current YTD])

 

-- Try to convert text to numeric

VAR ActualVal = VALUE(Actual)

VAR TargetVal = VALUE(Target)

VAR CurrentVal = VALUE(Current)

 

RETURN

SWITCH(

    TRUE(),

    ISBLANK(CurrentVal), BLANK(), -- No data

    CurrentVal >= TargetVal, "Green",

    CurrentVal < TargetVal && CurrentVal > ActualVal, "Yellow",

    CurrentVal < TargetVal && CurrentVal <= ActualVal, "Red",

    BLANK()

)

 

Thanks,
 Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

I got error.

 

Gopiraju404_0-1749207374240.png

Please help

Thank you.

Hi @Gopiraju404 , 

The error occurs because the column you're using contains mixed data types such as percentages, text (like "N/A"), and numbers. DAX formulas require consistent data types to perform calculations. In this case, values like "N/A" are text and cannot be converted to numbers, which causes the error.

To fix this issue, you need to make sure that the column contains only numeric values. This means you should either:

  • Remove the non-numeric values (like "N/A"), or
  • Replace them with a valid numeric value, such as 0 or BLANK() depending on your logic.

This will ensure that DAX can process the data correctly.

Hi @Gopiraju404,

Could you please provide sample data of .pbix file

This is sample data.

Gopiraju404_0-1749213502211.png

 

Please help

Thank you.

Hi @Gopiraju404,

I want to see how the data is in .pbix file(BI report)

Helpful resources

Announcements
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.