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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TuckRhodes
Helper I
Helper I

Clustered Bar Chart Functional Bar Coloring

Hello all!

 

I have a clustered bar chart with this year sales and last year sales as the bars. I want to have this years bar be colored red or green depending on if sales for that category exceeds that of last year. Is this possible

2 REPLIES 2
Anonymous
Not applicable

Hi  @TuckRhodes ,

I created some data:

vyangliumsft_0-1667271135237.png

Here are the steps you can follow:

1. Create measure.

Measure =
var _lastyear=
SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(TODAY())-1),[Amount])
var _currentyear=
SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(TODAY())),[Amount])
return
SWITCH(
    TRUE(),
    YEAR(MAX('Table'[Date]))=YEAR(TODAY())&&_currentyear > _lastyear,"red",
    YEAR(MAX('Table'[Date]))=YEAR(TODAY())&&_currentyear <= _lastyear,"green",
    "blue")

2. Format – Bars – Colors -- fx.

vyangliumsft_1-1667271135242.png

3. Enter the Default color interface.

vyangliumsft_2-1667271135245.png

4. Result:

vyangliumsft_3-1667271135248.png

 

Best Regards,

Liu Yang

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


6-Grouped-Bar-Chart.pngHello Liu!

 

Thanks for taking the time to provide an answer. Unfortunately, this isn't quite the scenario I was trying to describe. My sitiuation is better depicted by the above photo. Along the Y axis I have category of sales (as the main purpose of the page is to break down sales by category) and along the X axis is sales amount. Each category has two bars depending on what year it was sold but the bars come in pairs for each category just as in the image above the letters at the bottom have two bars each. So, to try and rephrase more appropriately, would there be a way to change the color of the orange(ish) bar to red or green contingent upon whether or not it is greater than the darker colored bar in each category? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.