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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
user365576
Helper I
Helper I

Color a column based on the values of another column

Hello everyone,

 

I want the column Next PRD Date to be colored based on the values of the Actual Delivery Date column. More specifically, if the date is earlier than the corresponding date (same row) in the Actual Delivery Date column, then i want the cell in the Next PRD Date to be colored green (indicative of desired scenario). Alternatively, if the date is later i want it to be colored red (indicator of unwanted script).

Any guesses how can I implement it?dates.png

1 ACCEPTED SOLUTION

hI @user365576 ,

You created a DateComparison calculated column by comparing a measure with a column. While that is not necessarily incorrect, the [Next PRD Date] in the rows of your calulcated column might be comparing a different date than what it appears in the visual thus you're getting an unexpected result. 13/12/204 is not earlier than 8/7/2024.  Use a measure so the two dates are compared within the context of the matrix visual.

IF (
    [Next PRD Date] < SELECTEDVALUE ( 'Open SO Orders'[Actual Delivery Date] ),
    "Later",
    "Earlier"
)

The formula above is very similar to what i initially proposed.

danextian_0-1720691280459.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

9 REPLIES 9
bhanu_gautam
Super User
Super User

@user365576 , You can create new calculate column and use it in rules

 

DateComparison =
IF (
'YourTable'[Next PRD Date] < 'YourTable'[Actual Delivery Date],
"Green",
"Red"
)

 

Go to the Report View.
Select the visual (e.g., table or matrix) that contains the "Next PRD Date" column.
Click on the dropdown arrow next to the "Next PRD Date" column in the Values area of the visualizations pane.
Select Cell elements > Background color or Font color.

PBIX is attached 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Both the solutions you gave me don't work correctly. Some dates are colored the way they are supposed to but some others don't

Can you explain which are not coloured the way they are supposed it is just sample data , you can check measure and condition in conditional formatting if you need to change something 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Take a look at the screenshots below which show some examples of the incorrect implementation:
1) DateComparison Column

earlier-later.png

2) Color Formatting
color.png

hI @user365576 ,

You created a DateComparison calculated column by comparing a measure with a column. While that is not necessarily incorrect, the [Next PRD Date] in the rows of your calulcated column might be comparing a different date than what it appears in the visual thus you're getting an unexpected result. 13/12/204 is not earlier than 8/7/2024.  Use a measure so the two dates are compared within the context of the matrix visual.

IF (
    [Next PRD Date] < SELECTEDVALUE ( 'Open SO Orders'[Actual Delivery Date] ),
    "Later",
    "Earlier"
)

The formula above is very similar to what i initially proposed.

danextian_0-1720691280459.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

This actually worked, but what about the dates that are same? They are labeled as "Later" while i want them null. Can you help me with this one too?

user365576_0-1721038303044.png

 

Anonymous
Not applicable

Hi @user365576 ,

Based on the description, try to add the if condition.

IF (
    [Next PRD Date] < SELECTEDVALUE ( 'Open SO Orders'[Actual Delivery Date] ),
    "Later",
    IF([Next PRD Date] > SELECTEDVALUE ( 'Open SO Orders'[Actual Delivery Date]),
    "Earlier", "NULL")
)

 

Best Regards,

Wisdom Wu

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

Can you check data type or just export both the date columns in excel and share here so, that I can check at my end




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






danextian
Super User
Super User

Hi @user365576 ,

 

Select field value from the conditional formatting options and use this measure:

Color =
IF (
    SELECTEDVALUE ( 'table'[Column1] ) < SELECTEDVALUE ( 'table'[Column2] ),
    "green"
)
--replace green with a  hexadecimal, RGB or RGBA value
--some color names do not have a  built-in color equivalent in Power BI, example is fuschia




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Solution Authors
Top Kudoed Authors