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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

@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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.