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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
JoelTib
Frequent Visitor

Dynamic Stacked Bar Chart

Hello Everyone,

 

I am hoping for some help with how to change the legend items displayed on a stacked bar chart based on a selection made with a filter. 

 

In short, we record the number of incidents that occur by several different clients.  We also record the severity of each incident.  However, for some clients the severity of the incidents ranges from 1 to 5, and for other clients the severity ranges from 1 to 10.  

 

When I select a client (from a slicer) whose severity ranges from 1 to 5, I would only like to see "Sev 1", "Sev 2", "Sev 3", "Sev 4" and "Sev 5" listed in the legend of the stacked bar chart.  When I select a client whose severity ranges from 1 to 10, I would like the legend to list severity levels from 1 to 10.  

 

To provide some visual assistance, the screenshot below shows the current stacked bar chart (I have implemented) for a client with a severity scale from 1 to 5... I would love for this chart just to show the severity items from 1 to 5 in this case... however, for clients with severity ranging from 1 to 10, I'd love the stacked bar chart to look like this below (with legend ranging from Sev 1 to Sev 10).  

 

Severity .jpg

 

Any assistance with this would be very warmly appreciated.

 

Kind regards,

Joel

2 REPLIES 2
JoelTib
Frequent Visitor

Hi @TomMartens,

 

Thank you very much for your reply.  I really appreciate your help.  

 

I do see that the legend is dynamic and I am able to replicate this with my own file. 

 

Just to provide a little more detail, in my dataset I have a variable listing the severity of each episode.  I have then constructed conditional columns for each severity level, from 1 to 10 - so, if for example, an incident of severity level 7 is recorded, it will be listed in the original severity variable (as the number 7) and then also recorded in the constructed conditional column titled "7" with a number 1.  To construct the stacked column chart in the screenshot I provided above, I used the conditional columns that I constructed.  

 

I am still relatively new to Power BI, but I have made use of Field Parameters in previous dashboards I have built up.  I guess I was wondering if there may be a solution to my question using Field Parameters, DAX expressions... or some other method?

 

Again, thank you very much for your help.

 

Kind regards,

Joel

TomMartens
Super User
Super User

Hey @JoelTib ,

 

basically the legend is dynamic by default, see the gif

Stacked Bar Chart - Dynamic Legend.gif

Maybe you checked the option "Show Items with no data": 

TomMartens_0-1687755344860.png

If this is the case and you did this intentionally, then there is no way to achieve what you are looking for. The reason for this is simple: You can not define the content for the legend based on a condition like "customer tpye."

The content is for the legend is data or all values.

Hopefully, this provides some additional insights.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors