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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Pbiuserr
Post Prodigy
Post Prodigy

Conditionally colour of bar by year

Hello,

I've created a measure to color a bar in a chart based on user selection

 

Colors =
VAR _CurrentYear = YEAR(MAX('Calendar'[Date]))
RETURN
SWITCH(
TRUE(),
_CurrentYear - 3, "#00d600",
_CurrentYear - 2, "#d60000",
_CurrentYear, "#24297A"
)
 
Somehow I can't let it work. So it would be like - If user click on 2015 then it would be "#24297A" for 2015, "#d60000" for 2014 and "#00d600" for 2013 and so on. If they click 2022 then on then it would be "#24297A" for 2022, "#d60000" for 2021 and "#00d600" for 2020 etc
 
How to do that?
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Pbiuserr 

 

You need to create a Year table for the slicer and make this table disconnected from Calendar table. 

vjingzhang_1-1652338550389.png

 

Then use the following measure

Colors = 
VAR _CurrentYear = SELECTEDVALUE('Year'[Year])
RETURN
SWITCH(
TRUE(),
MAX('Calendar'[Year]) = _CurrentYear - 2, "#00d600",
MAX('Calendar'[Year]) = _CurrentYear - 1, "#d60000",
MAX('Calendar'[Year]) = _CurrentYear, "#24297A"
)

 

I have created a sample. Please download the attachment to see details. 

vjingzhang_0-1652338490548.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @Pbiuserr 

 

You need to create a Year table for the slicer and make this table disconnected from Calendar table. 

vjingzhang_1-1652338550389.png

 

Then use the following measure

Colors = 
VAR _CurrentYear = SELECTEDVALUE('Year'[Year])
RETURN
SWITCH(
TRUE(),
MAX('Calendar'[Year]) = _CurrentYear - 2, "#00d600",
MAX('Calendar'[Year]) = _CurrentYear - 1, "#d60000",
MAX('Calendar'[Year]) = _CurrentYear, "#24297A"
)

 

I have created a sample. Please download the attachment to see details. 

vjingzhang_0-1652338490548.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Arul
Super User
Super User

@Pbiuserr ,

 

This solution in this thread would help you,

https://community.powerbi.com/t5/Desktop/Conditionally-format-bar-chart-column-colour-based-on-slice... 

 

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Can you share more details on how to achieve this? I can't figure it out 

@Pbiuserr , You need to create disconnected table and then create a measure for conditional formatting.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

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.