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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
RolledNatural1
New Member

How to compare the values of two Columns, and colour the column cells based on the comparison?

Hi, I'm quite new with Power BI, and am now trying to figure out how ow to compare columns in the same table and colour the cells based n the comparison. I've tried to look for the answer, but sadly haven't been able to find one for this.

 

How can I compare the values of two Columns, and colour the column cells based on the comparison? Please see the details below.

 

EXAMPLE

 

Comparison 1
Comparing columns B and C. If the value of column C is equal or higher than the value in column B, the cell in column B is coloured red.

 

Comparison 2
Comparing columns D and E. If the value of column E is less than the value in column D, the cell in column D is coloured red.

table_example.png

1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

@RolledNatural1 

Kedar_Pande_0-1729225814470.png

Create a measure:

CF Col2 =
IF(SUM('Table'[Col 2])> SUM('Table'[Col 1]), "Orange")


Apply background fx based on this measure

Kedar_Pande_1-1729225890210.png

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

View solution in original post

4 REPLIES 4
RolledNatural1
New Member

Thank you all for the help, I really, really appreciate the help - took me a while, but finally got there.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the  below picture and the attached pbix file.

And FYI, the link down below is from Microsoft Learn.

Apply conditional table formatting in Power BI - Power BI | Microsoft Learn

 

Jihwan_Kim_0-1729227526684.png

 

Jihwan_Kim_1-1729227585923.png

 

 

background color condition: =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( category[Index] ) = 2,
        IF (
            CALCULATE (
                [Sum value:],
                FILTER (
                    ALL ( category ),
                    category[Index] = 2
                )
            )
                >= CALCULATE (
                    [Sum value:],
                    FILTER (
                        ALL ( category ),
                        category[Index] = 1
                    )
                ),
            "Red"
        ),
    SELECTEDVALUE ( category[Index] ) = 4,
        IF (
            CALCULATE (
                [Sum value:],
                FILTER (
                    ALL ( category ),
                    category[Index] = 4
                )
            )
                <= CALCULATE (
                    [Sum value:],
                    FILTER (
                        ALL ( category ),
                        category[Index] = 3
                    )
                ),
            "Red"
        )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Ritaf1983
Super User
Super User

Hi @RolledNatural1 
In the first step, you should create measures for every metric like :

Current Forecast = sum('Table'[Current Forecast (eur)])

Ritaf1983_0-1729226543571.png

after you have all of them you can create a dax code with the condition and color ( by hexa code or a name) :

Hours_color = if([Current Hours]>=[Original Estimate h],"#FF7575","white")
and then you can use the condition measure as a format option of the wanted column :
Ritaf1983_1-1729226664666.pngRitaf1983_2-1729226688574.png

Result :

Ritaf1983_3-1729226712145.png

the pbix is attached

More guides about conditional formatting here:

https://www.youtube.com/watch?v=mcVoVSXhWmw

https://www.youtube.com/watch?v=m0h3Ghl6mgY

https://www.youtube.com/watch?v=0aifKG_EEYk

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Kedar_Pande
Super User
Super User

@RolledNatural1 

Kedar_Pande_0-1729225814470.png

Create a measure:

CF Col2 =
IF(SUM('Table'[Col 2])> SUM('Table'[Col 1]), "Orange")


Apply background fx based on this measure

Kedar_Pande_1-1729225890210.png

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors