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

Change of bar color based on date - before and after today

Is it possible to change the color of the bars in a chart, based on date? Values today and after today has another color than before today. I am using this on sales - values to be delivered, and values of backlog

1 ACCEPTED SOLUTION
Aditya_Meshram
Solution Supplier
Solution Supplier

Hi @Anonymous , you can achieve this by following these steps.

1)Create a column in your table for holding the difference in date with respect to today's date in days. You can use the following DAX for the column.

Date Difference = DATEDIFF(TODAY(),Sheet1[Sample Date ],DAY)

You'll get a column like this

Aditya_Meshram_0-1625832502608.png

2)Create a bar chart and use conditional formatting based on the Date Difference column to get different colours for values having date equal to and greater than today and for values having date less than today. Go to conditional formatting by clicking on fx Button(Shown below)

Aditya_Meshram_1-1625832870250.png

 

3) Then you can can set the "Format by"  field as "Rules" and use the following rules.

Aditya_Meshram_2-1625833007572.png

The result will look like this. The values with negative date difference have red colour and the values with zero and positive date difference have green colour.

Aditya_Meshram_3-1625833349438.png

The date as of writing this answer is 9th July 2021, so the values for 9th July and above have green color and the values having date before 9th July have red colour.

 

The .pbix file is attached for reference.

Link to the .pbix file. 

 

Regards,

Aditya

 

View solution in original post

6 REPLIES 6
Rui_Reis
Frequent Visitor

I don't see the option to get conditional formating am I using the wrong chart type or version?
I'm using clustered columns chart and line and clusteres columns chart.

Rui_Reis_0-1676549205326.png

 

lcdelgado
Helper I
Helper I

The operations Qtr1 have 3 with -5 days and its not red on the column. I appreciate any help on this matter, thank you 🙁

 

lcdelgado
Helper I
Helper I

Hello! why my graphic doesnt show the red color on the negative values on my graph?

 

lcdelgado_1-1673896051492.png

lcdelgado_2-1673896068640.png

 

Anonymous
Not applicable

This was also exactly what I was looking for - thank you!  I have a 13-month rolling trend chart and wanted to highlight last month vs. last month prior year.  Using your formula to create a "Months Ago" column in my date table did the trick.

 

2022-08-11 11_35_05-KevAnne's Expenses Dashboard - Power BI Desktop.png2022-08-11 11_35_41-KevAnne's Expenses Dashboard - Power BI Desktop.png

Anonymous
Not applicable

Thank you! This is what I'm looking for!

 

Best regards, Ingrid 

Aditya_Meshram
Solution Supplier
Solution Supplier

Hi @Anonymous , you can achieve this by following these steps.

1)Create a column in your table for holding the difference in date with respect to today's date in days. You can use the following DAX for the column.

Date Difference = DATEDIFF(TODAY(),Sheet1[Sample Date ],DAY)

You'll get a column like this

Aditya_Meshram_0-1625832502608.png

2)Create a bar chart and use conditional formatting based on the Date Difference column to get different colours for values having date equal to and greater than today and for values having date less than today. Go to conditional formatting by clicking on fx Button(Shown below)

Aditya_Meshram_1-1625832870250.png

 

3) Then you can can set the "Format by"  field as "Rules" and use the following rules.

Aditya_Meshram_2-1625833007572.png

The result will look like this. The values with negative date difference have red colour and the values with zero and positive date difference have green colour.

Aditya_Meshram_3-1625833349438.png

The date as of writing this answer is 9th July 2021, so the values for 9th July and above have green color and the values having date before 9th July have red colour.

 

The .pbix file is attached for reference.

Link to the .pbix file. 

 

Regards,

Aditya

 

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.