Forum Discussion

Justas4478's avatar
Justas4478
Post Prodigy
1 year ago
Solved

Stacked column chart with dynamic legend

Hi, I created this chart in excel.

As you see it shows legend with the data and it is dynamic and changes with the filters.
I am trying to create same chart in power bi but I cant best I done is this.

As you see at the bottom is just simple matrix table that does not automaticly line up like the one is excel does.
Does anyone know if there is chart that can get result I want or any in the visual store.
Thanks

  • v-tejrama's avatar
    v-tejrama
    1 year ago

    Hi Justas4478 ,

     

    Thank you for the update and for trying the suggested option. The custom visual may not fully match Excel’s dynamic legend alignment because Power BI’s visuals, both native and custom, don’t replicate this feature exactly. The best way to achieve similar behaviour is by reshaping your data model using Unpivot Columns and then creating the stacked column chart as previously described. This setup allows the legend to update dynamically with filters, which addresses your main requirement. Although the result may not look exactly like Excel, it is currently the most reliable and supported method in Power BI.

    If you need a closer match, you could explore other visuals in AppSource, but the unpivot and stacked column chart remains the most consistent and flexible solution.

    Thank you,

    Tejaswi.

7 Replies

  • Daniel29195's avatar
    Daniel29195
    Community Champion

    Justas4478 

    2 solutions for such a visual  
    solution 1 ; ( easy approach ) 
    use the custom visual : 

    if the number of values in the legend is fixed ,  then you can create a measure per each group . 

     

     

    solution 2 : ( more complex  dax approach ) 

    Bas on youtube did create a visual using native power bi  visual and dax,  to create a line chart with table below it. 

    i honestly cant remember the name of the video,  but it was on the channel :  how to powerbi ( by bas )

     

     

    for me, i would go with the first solution. easier .

     

     

    hope this helps . 

  • Hi Justas4478 

     

     I haven't seen a chart like that.

    What I would recommend is using tooltips to display the information when hovering over the bars.

    For even more detail, create a tooltip page that will show visual information.

  • v-tejrama's avatar
    v-tejrama
    Community Support

    Hi Justas4478 ,

     

    You can easily create a stacked column chart with a dynamic legend in Power BI by making a few adjustments to your data. Here’s how you can do it:

    1. Import your data into Power BI (Home → Get Data → Excel/CSV).
    2. Open Transform Data (Power Query).
    3. Select your difference columns (such as Diff1, Diff2, Diff3).
    4. Right-click and select Unpivot Columns. This will generate two new columns: one for the difference type (e.g., Diff1, Diff2, Diff3) and one for the values.
    5. Rename these columns (for example, “Difference Type” and “Amount”), then choose Close & Apply.
    6. Add a Stacked Column Chart visual.
    7. Assign StorageType to the Axis, Difference Type to the Legend, and Amount to the Values.

    With this setup, your legend will dynamically update when filters are applied, just like in Excel. For a table below the chart, simply add a Matrix visual using StorageType as rows, Difference Type as columns, and Amount as values. This approach will deliver the results you need.

    I’ve attached the .pbix file and screenshots for your reference.

     

    Thank you,

    Tejaswi.

    • v-tejrama's avatar
      v-tejrama
      Community Support

      Hi Justas4478 ,

      I wanted to follow up and see if you had a chance to review the information shared. If you have any further questions or need additional assistance, feel free to reach out.

      Thank you.

       
      • Justas4478's avatar
        Justas4478
        Post Prodigy

        I tried the proposed custom visual form visual store unfortuantelly it does not function as I was hoping.
        I will try to see maybe I can find other solutions.