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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
admin11
Memorable Member
Memorable Member

How to make last bar red color ?

Hi All

I have below expression from Mr Amit , it can help me color the latest year red color :-

Color Last Bar = var _max = maxx(ALLSELECTED('Date'), 'Date'[YrMth Sort]) return if(max('Date'[YrMth Sort]) = _max, "Red")
it work fine when i X axis = year 
admin11_0-1611209078006.png

Remark :- for the above sales by YrMthSort bar chart , when i filter year=2020 , the Dec bar will color red.

But for my case i cannot filter .

 

How to make it work when X axis = YearMthSort ?
Above link is my PBI file
 
Paul Yeo
 
 

 

1 ACCEPTED SOLUTION
Rigensis
Resolver I
Resolver I

@admin11 

The reason why the last column is not colored Red is because the evaluation of max YrMthSort is giving back the very last field, which in your case was end of 2021.

I changed the Date table range to having max date of Today.

 

Date = CALENDAR(Date(2000,01,01),Today())

Then when your calculation evaluates the max YrMthSort it colors the last bar in the visual

lastcolRed.png

View solution in original post

3 REPLIES 3
Rigensis
Resolver I
Resolver I

@admin11 

The reason why the last column is not colored Red is because the evaluation of max YrMthSort is giving back the very last field, which in your case was end of 2021.

I changed the Date table range to having max date of Today.

 

Date = CALENDAR(Date(2000,01,01),Today())

Then when your calculation evaluates the max YrMthSort it colors the last bar in the visual

lastcolRed.png

@Rigensis Many thank for your help , now it work fine now.

Below is my orginal date expression :-

Date = CALENDAR(Date(2000,01,01),date(2021,12,31))

Below is your propose date expression to make latest month bar turn red.

My question is after changing to your date expression :-

Date = CALENDAR(Date(2000,01,01),Today())

will it affect on my other report ? I did a quick check it seen to work fine. Look like your expression on date is the best.

 

Paul Yeo

 

amitchandak
Super User
Super User

@admin11 ,

You have to create a color measure and use that in data color advance option with "Field value"

 

COlor year =

var _maxx(allselected(Date),Date[Year])

return

if(Max(Date[Year]) = _max , "red", "blue")

 

 

refer for step

Color Field - Color Measure - Conditional formatting
https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values
https://youtu.be/M5PvQUy-L_4?t=531

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
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.