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
kevbrown1980
Frequent Visitor

Format bar chart colours

Hi

 

I have a bar chart that needs to show colour changes depending on whether the values have increased or decreased from the previous Month.

 

For example - 

 

I have a calculated field called MOM Fruit

 

Jan = 19

Feb = 26

Mar = 14

Apr = 6

May = 8

 

So, I need Feb to be Red, Mar Green, Apr Green and May Red

 

Any help would be great

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @kevbrown1980 ,

I created some data:

vyangliumsft_0-1645675237744.png

Here are the steps you can follow:

1. Create measure.

Color =
var _current=CALCULATE(SUM('Table'[MOM Fruit]),FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))))
var _last=CALCULATE(SUM('Table'[MOM Fruit]),FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(MAX('Table'[Date])-1)))
var _if=
IF(
    _last=BLANK(),_current,_last)
var _su=
_current - _if
return
SWITCH(
    TRUE(),
    _su=0,"blue",
    _su>0,"red",
    _su<0,"green")

2. Click Visual - Format - Data colors -- fx

vyangliumsft_1-1645675237745.png

3. Enter the Default color interface.

Format style – Field value

What field should we base this on – [color]

vyangliumsft_2-1645675237746.png

4. Result:

vyangliumsft_3-1645675237748.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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @kevbrown1980 ,

I created some data:

vyangliumsft_0-1645675237744.png

Here are the steps you can follow:

1. Create measure.

Color =
var _current=CALCULATE(SUM('Table'[MOM Fruit]),FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))))
var _last=CALCULATE(SUM('Table'[MOM Fruit]),FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(MAX('Table'[Date])-1)))
var _if=
IF(
    _last=BLANK(),_current,_last)
var _su=
_current - _if
return
SWITCH(
    TRUE(),
    _su=0,"blue",
    _su>0,"red",
    _su<0,"green")

2. Click Visual - Format - Data colors -- fx

vyangliumsft_1-1645675237745.png

3. Enter the Default color interface.

Format style – Field value

What field should we base this on – [color]

vyangliumsft_2-1645675237746.png

4. Result:

vyangliumsft_3-1645675237748.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

SteveHailey
Solution Specialist
Solution Specialist

Hello @kevbrown1980.

Assuming you have a date table, you could create a measure using this pattern:

Bar formatting =
VAR PriorMonthMOMFruit =
    CALCULATE ( SUM ( 'Table'[MOM Fruit] ), DATEADD ( 'Date'[Date], -1, MONTH ) )
VAR CurrentMonthMOMFruit =
    CALCULATE ( SUM ( 'Table'[MOM Fruit] ) )
VAR Result =
    IF ( ( CurrentMonthMOMFruit - PriorMonthMOMFruit ) > 0, "Green", "Red" )
RETURN
    Result

Note that you can replace "Green" and "Red" with hex values if you want to fine-tune the shade of the colour.


Then, select your bar chart, and in the visualization pane, under Data colors, click the "fx" button:

SteveHailey_0-1643806183849.png

On the next screen, under the "Format style" drop-down at the top, choose "Field value".

Then, under "What field should we base this on", choose the measure you created above.

Your results should look something like this:

SteveHailey_1-1643806262869.png

I created a .pbix file here that you can download if it is helpful.

 

-Steve

amitchandak
Super User
Super User

@kevbrown1980 , create a measure like this example and use it conditional formatting using field value option

 

Colour =
SWITCH(TRUE(),
max('Table'[Month]) = "Feb", "red",
max('Table'[Month]) = "Mar", "Green",

max('Table'[Month]) = "Apr", "Green",

max('Table'[Month]) = "May", "Red",
//keep on adding
"green")

 

How to do conditional formatting by measure and apply it on pie?: https://youtu.be/RqBb5eBf_I4

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.