cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Let
Frequent Visitor

How to sort stacked column chart in Power BI desktop?

Hello,

 

I would like to sort a stacked bar in Power BI.

However, the option button at the top-right corner doesn't seem to provide the sort feature.

 

Screenshot_1.png

 

Here are the sort criteria I want:

1. The longest bar first

2. The bar of which the green part is the longest first

Repeat the 2. again and again for the other colors.

 

Is that possible?

 

I tried this tutorial, but I had 2 problems

1. I couldn't implement the last step

2. The tutorial is not really what I want.. I want the sort options available right from the top-right button instead of in another table.

 

Here is the last step of the tutorial

 

With that in place, go to the Data view and add a New Column to the main table.

Sort Order = RELATED(AuxTable[Sort Order])

 

 

-----------------------------------

 

My current stacked column settings are:

- Axis: number

- values: number

- Legend: text

 

Example of data:

 

[
    {
        "x": 1,
        "y": 1000,
        "type": "car"
    },
    {
        "x": 2,
        "y": 3000,
        "type": "car"
    },
    {
        "x": 3,
        "y": 5000,
        "type": "car"
    },
    {
        "x": 1,
        "y": 10000,
        "type": "plane"
    },
    {
        "x": 2,
        "y": 13000,
        "type": "plane"
    },
    {
        "x": 3,
        "y": 9000,
        "type": "plane"
    },
    {
        "x": 1,
        "y": 2000,
        "type": "bike"
    },
    {
        "x": 2,
        "y": 4500,
        "type": "bike"
    },
    {
        "x": 3,
        "y": 8000,
        "type": "bike"
    }
]

 

 

1 ACCEPTED SOLUTION

Hi @Let,


The sort "The longest bar first" is available if the x-axis is type of Text.

How can I make it work even with numbers (for consistency) ? (Besides, if x-axis is the type of Text, the chart has an horizontal scrollbar)


To make the sort option work with numbers, you can just set X-Axis Type to "Categorical". However, with this option, all labels will be shown on the X-Axis, so an horizontal scrollbar will be shown up if the chart is not big enough. Smiley Happy

 

r2.PNG

 

Regards

View solution in original post

8 REPLIES 8
Let
Frequent Visitor

Update:

The sort "The longest bar first" is available if the x-axis is type of Text.

How can I make it work even with numbers (for consistency) ? (Besides, if x-axis is type of Text, the chart has an horizontal scrollbar)

Where can I find the option to sort by "Longest Bar First"?

Oh, there it is. I'm posting a picture here to help the next lost Dashboarder. It'll be in the top right of your visualization.

 

SortByCount 20180207.jpg

Hi comish, I don't think this preserved the sort order of the x-axis. Choosing that "Sort by Count of Change Type" makes the x-axis resorted by the x-axis values with highest bar (regardless of individual color size within a bar) to the lowest.

 

Hi Let,

In my stack bar,

Axis:       text. Shown in ascending order. I am okay with this

Legend: text.

Value:    Count of the column in legend. 

 

I am still trying to figure out: while preserving the sort order of the x-axis (Data type: text, sorted ascending), how to sort longest bar first within each x-axis bar? Longest bar to shortest bar is determined by Value.

 

Any help is appreciated.

Hi,

I'm experiencing the same problem I've searched for the option longest bar first but I cannot find it.
My X-axis is of  type text and the values are a count of type whole number.
Untitled.png
Any suggestions.

Cheers

Can you please tell me how did you create a stcked bar chart with x-axis different data colors ?

 

Hey,

 

You already find a solution for this problem? I am facing the samen problem at the moment..

Hi @Let,


The sort "The longest bar first" is available if the x-axis is type of Text.

How can I make it work even with numbers (for consistency) ? (Besides, if x-axis is the type of Text, the chart has an horizontal scrollbar)


To make the sort option work with numbers, you can just set X-Axis Type to "Categorical". However, with this option, all labels will be shown on the X-Axis, so an horizontal scrollbar will be shown up if the chart is not big enough. Smiley Happy

 

r2.PNG

 

Regards

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.