Forum Discussion

swong's avatar
swong
Helper II
9 years ago
Solved

stacked graph order

Hi,

 

I have a stacked bar chart, and the different segments are:

 

Exact, Full, Partial, Traditional

 

My bars are stacked in that order (alphabetical), with "Exact" on the bottom and "Traditional" on top. However, I want my segments to be ordered the opposite, with "Traditional" on bottom and "Exact" on top.

 

I created a Sort table, with each of my segments and it's corresponding order, e.g. (Traditional, 1), (Partial, 2). I then added a column to my original table:

 

Sort Order = RELATED(SortTable[Sort Order])

 

and sorted the original table by this column. However, this didn't change the order of segments in my stacked bar chart. How can I make the chart reflect my custom ordering?

  • Hi swong,

     

    Currently, it is not supported to sort the chart based on legend. Someone has submitted this feature request, you can clisk to vote it up. Custom order for legend in stacked bar chart

     

    As a workaround, you could create Measures for each segment. Then place each Measure in the Values area in the order you need. However, this workaround might not apply to the scenario where you have many legend items.

     

    Regards,
    Yuliana Gu

11 Replies

  • wynhopkins's avatar
    wynhopkins
    Most Valuable Professional

    I think I have a solution to this.

     

    If you set up a separate Table (use Enter Data) containing Exact, Full, Partial, Traditional  and then type 1,2,3,4 in the column next to it you can then connect that to your table that is currently being used in your chart.

     

    Use this new column of of segment names in your chart instead of the original ones.

     

    You can then use the Sort By Column option under Modelling to get your segments to show any order you want.

  • MattAllington's avatar
    MattAllington
    Community Champion

    Have you tried sorting from the ellipsis in the top right corner of the chart. Not sure if that affects the stack order or not

    • swong's avatar
      swong
      Helper II

      Hm I'm not getting the option to sort -- my only options are:

       

      • MattAllington's avatar
        MattAllington
        Community Champion

        Sorry, I'm not at my PC so didn't check. I thought all charts had a sort feature there 

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi swong,

     

    Currently, it is not supported to sort the chart based on legend. Someone has submitted this feature request, you can clisk to vote it up. Custom order for legend in stacked bar chart

     

    As a workaround, you could create Measures for each segment. Then place each Measure in the Values area in the order you need. However, this workaround might not apply to the scenario where you have many legend items.

     

    Regards,
    Yuliana Gu

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks, using measures,  has solved my upside down traffic light

      • Anonymous's avatar
        Anonymous
        Not applicable

        Can you share your measure?

    • Anonymous's avatar
      Anonymous
      Not applicable

      The proposed workaround of using measures for sorting is not acceptable for my organization's purposes.  By using measures in place of a single Legend column, we lose the ability to filter or drill from the individual bar segments.

       

      UPDATE: I found a solution that worked for me.  In involves setting the "Sort By Column" property on the column itself, either in the embedded Power BI model or in SSAS.  For more info, see here: https://stackoverflow.com/questions/51156029/how-to-sort-a-bar-chart-in-microsoft-power-bi-desktop

       

       

  • You can also solve this simply by creating separate measures for each variable you would like to show on the stacked chart. You can then order them as you wish in the column values field under Visualisations.

  • Betacom's avatar
    Betacom
    Frequent Visitor

    The workaround that worked for us:

    The legend is sorted by symbols then numbers then alphabetically.  I was able to adjust the caculated measure column result (legend) descriptions to adjust the ordering.

     

    So, in my case:

    < 6  Days

    06-14 Days

    14+ Days

    Average Days