Forum Discussion

JoelTib's avatar
JoelTib
Frequent Visitor
3 years ago

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

 

 

Any assistance with this would be very warmly appreciated.

 

Kind regards,

Joel

2 Replies

  • Hey JoelTib ,

     

    basically the legend is dynamic by default, see the gif

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

    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

  • JoelTib's avatar
    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