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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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

11 REPLIES 11
taha_mansoor
Frequent Visitor

@Let @v-ljerr-msft  This option is not there. Is there any solution to this problem as of now ?

NotMyJob
Helper II
Helper II

Maybe this used to work, however now there is not a 'Type' element under either of the axis sections.  

 

NotMyJob_0-1675196294962.png

 

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

Thank you so much - it's not easy to find! Worked a charm for me.

 

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors