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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to change background color of cells in a table, based on comparing column values

Hello,

 

In my PBI project, I have a report with a standard table.

I need to compare the values in 2 columns and change the background color of the specific cell based on values.

Two columns are named "Plan_Hours" and "Actual_Hours".

If Plan_Hours > Actual_Hours Then

     Set Plan_Hours.BackgroundColor = GREEN

End

If Plan_Hours < Actual_Hours Then

     Set Actual_Hours.BackgroundColor = RED

End

Is this something I need to do using DAX or is there another way.

Thanks in advance,

Rich

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Anonymous Yes, DAX and use Conditional Formatting with Rules. Something like:

Measure = IF(MAX([Plan_Hours])<MAX([Actual_Hours]),1,0)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-yetao1-msft
Community Support
Community Support

Hi @Anonymous 

Create two measures for 'Table'[Actual_Hours] and 'Table'[Actual_Hours] separately .

Plan hours = IF(SELECTEDVALUE('Table'[Plan_Hours])>SELECTEDVALUE('Table'[Actual_Hours]),"Green")
Actual hours = IF(SELECTEDVALUE('Table'[Plan_Hours])<SELECTEDVALUE('Table'[Actual_Hours]),"Red")

Then in Visual Fields , set conditional formatting for the two fields .

Ailsamsft_0-1630048773139.png

Ailsamsft_1-1630048773140.pngAilsamsft_2-1630048773142.png

The final result is as shown :

Ailsamsft_3-1630048773142.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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

View solution in original post

2 REPLIES 2
v-yetao1-msft
Community Support
Community Support

Hi @Anonymous 

Create two measures for 'Table'[Actual_Hours] and 'Table'[Actual_Hours] separately .

Plan hours = IF(SELECTEDVALUE('Table'[Plan_Hours])>SELECTEDVALUE('Table'[Actual_Hours]),"Green")
Actual hours = IF(SELECTEDVALUE('Table'[Plan_Hours])<SELECTEDVALUE('Table'[Actual_Hours]),"Red")

Then in Visual Fields , set conditional formatting for the two fields .

Ailsamsft_0-1630048773139.png

Ailsamsft_1-1630048773140.pngAilsamsft_2-1630048773142.png

The final result is as shown :

Ailsamsft_3-1630048773142.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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

Greg_Deckler
Super User
Super User

@Anonymous Yes, DAX and use Conditional Formatting with Rules. Something like:

Measure = IF(MAX([Plan_Hours])<MAX([Actual_Hours]),1,0)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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