cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
admin11
Post Prodigy
Post Prodigy

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
Helper I
Helper 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
Helper I
Helper 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

@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 IV
Super User IV

@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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power BI User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.