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

View all the Fabric Data Days sessions on demand. View schedule

Reply
cleslie
New Member

Dynamically set legend colors based on number of items selected

I have a clustered bar chart displaying Average Dialy Visits (counts) by month (count on y axis, month on x axis) collected at a number of different locations. I have a slicer allowing the end use to select 1 or more locations (there are 45 locations in total). In order to facilitate comparaison of monthly visitation counts for different locations, I am using the locations as the categories for the "Legend" field.

 

Typically, the end use will only select a few locations at a time (let's say a max of 3). However, by default Power BI assigns a static color to each category. What I would like to do is assign the legend colors dynamically based on the number of locations selected. For example, if only one location is selected it is always green. If two are selected, one is green and one is blue. If a third is selected, green, blue and yellow. Etc.

 

It really doesn't matter which location is assigned which color when selected so that isn't a constraint.

 

2 REPLIES 2
cleslie
New Member

I have a clustered bar chart displaying Average Dialy Visits (counts) by month (count on y axis, month on x axis) collected at a number of different locations. I have a slicer allowing the end use to select 1 or more locations (there are 45 locations in total). In order to facilitate comparaison of monthly visitation counts for different locations, I am using the locations as the categories for the "Legend" field.

 

Typically, the end use will only select a few locations at a time (let's say a max of 3). However, by default Power BI assigns a static color to each category. What I would like to do is assign the legend colors dynamically based on the number of locations selected. For example, if only one location is selected it is always green. If two are selected, one is green and one is blue. If a third is selected, green, blue and yellow. Etc.

 

It really doesn't matter which location is assigned which color when selected so that isn't a constraint.

 

Anonymous
Not applicable

Hi @cleslie,

 

Nope, current power bi not support this.

 

In fact, condition formatting feature support to use other column value to setting color, but you can't create dynamic calculate column/table based on slicer/filter to make color fields dynamic.

 

BTW, you can create dynamic measure based on slicer/filter, but it can't use on legend and axis fields.

 

Regards,

Xiaoxin Sheng

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors