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
MRUry7
Resolver II
Resolver II

Changing bar colors in bar chart based on more than one criteria.

Hi. I have a bar chart here. The arrows indicate if the value in the bar chart has changed positively, negatively or both, from the last time period.


If Positive, arrow right, if negative, arrow left and if now change, no arrow.
How do i get the colors in the bars to change depending on the same criteria? Easy to do if the only thing is checking the value of the bar, but what if the color is dependent not on just the value of the bar but whether or not it change +,- or neutral?

Right now I also have the arrows on top of each chart item, but of course that's not going to work when an item is added orr removed.  Is there a way to include the arrow as part of the bar itself?

MRUry7_0-1709583987700.png

Any help is appreciated.
Thanks, Steven.

1 ACCEPTED SOLUTION

@MRUry7 , You can use measure for the previous period like below, assuming you are using date table

 

//previous period
Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),DAY)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
Return
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date
)


Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),DAY)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
Return
CALCULATE(sum(Sales[Sales Amount]),dateadd('Date'[date],-1*_diff,Day)


//previous period month
Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),Month)+1
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Month))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Month))-1
Return
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date
)

 

 

Then you can use color measure

 

/////Arrow Color
Arrow color =
var _change =[This period]-[Same Date range last period]
return
SWITCH (
TRUE(),
_change > 0, "green",
_change = 0, "blue",
_change < 0, "red"
)

 

You can make the measure complex by using additional conditions. Use it in conditional formatting using field value option

 

 

For arrow, you can use label customization, this feature has been enhanced after i shared this video, but you can get icon with color

 

Measure driven data labels| How to use a different measure on label| Some interesting visuals: https://www.youtube.com/watch?v=Y6G1Rj_O7XE

 

 

Learn Power BI Advance - PowerBI Abstract Thesis:
How to do conditional formatting by measure and apply it on pie?
https://www.youtube.com/watch?v=RqBb5eBf_I4&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L
https://community.powerbi.com/t5/Community-Blog/Power-BI-Conditional-formatting-the-Pie-Visual/ba-p/...
https://amitchandak.medium.com/power-bi-where-is-the-conditional-formatting-option-in-new-format-pan...

View solution in original post

4 REPLIES 4
MRUry7
Resolver II
Resolver II

Thanks for responding.  That part I'm aware of doing. 
The challenge is that I have to compare it against a previous value of the same date range (ex. 1 month earlier), so what I have to do is to calculation the % as you have it, then also compare it to the previous value of the same thing.
ex. user choses 30 day range.  So the bar chart must show the difference and whether it went up or down; if up green, if down red, and if unchanged, another color.

That's where my challenge is.

@MRUry7 , You can use measure for the previous period like below, assuming you are using date table

 

//previous period
Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),DAY)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
Return
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date
)


Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),DAY)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
Return
CALCULATE(sum(Sales[Sales Amount]),dateadd('Date'[date],-1*_diff,Day)


//previous period month
Same Date range last period =
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),Month)+1
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Month))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Month))-1
Return
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date
)

 

 

Then you can use color measure

 

/////Arrow Color
Arrow color =
var _change =[This period]-[Same Date range last period]
return
SWITCH (
TRUE(),
_change > 0, "green",
_change = 0, "blue",
_change < 0, "red"
)

 

You can make the measure complex by using additional conditions. Use it in conditional formatting using field value option

 

 

For arrow, you can use label customization, this feature has been enhanced after i shared this video, but you can get icon with color

 

Measure driven data labels| How to use a different measure on label| Some interesting visuals: https://www.youtube.com/watch?v=Y6G1Rj_O7XE

 

 

Learn Power BI Advance - PowerBI Abstract Thesis:
How to do conditional formatting by measure and apply it on pie?
https://www.youtube.com/watch?v=RqBb5eBf_I4&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L
https://community.powerbi.com/t5/Community-Blog/Power-BI-Conditional-formatting-the-Pie-Visual/ba-p/...
https://amitchandak.medium.com/power-bi-where-is-the-conditional-formatting-option-in-new-format-pan...

Thanks, I will check out what you provided. Thank you.

v-rongtiep-msft
Community Support
Community Support

Hi @MRUry7 ,

Please try to use conditional format.You can adjust their background color based on negative and positive numbers as well as 0 pairs.

vrongtiepmsft_0-1709606699683.png

More details: Apply conditional table formatting in Power BI - Power BI | Microsoft Learn

 

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

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.