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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
jj304
Frequent Visitor

Sort 100% stacked bar chart by percentage descending order

Hi, I have a  power bi report using direct query that has a 100% stacked bar chart that displays the volume by users split by category.

 

The columns are

  • Y-axis - User 
  • X-axis - Sum of volume
  • Legend - Category

 I would like to sort the bars to display by percentage in descending order but currently it always sorts by the legend.  Any ideas how I can force it to sort by % volume.  Thanks

1 ACCEPTED SOLUTION

Hi @jj304 ,

 

Since we can't use measure for y-axis, to achieve this sorting effect, I suggest you create a calculated table:

NewTable = ADDCOLUMNS(
    'Table',
    "AdjustedUser1", IF(
        'Table'[Category] = "A",
        RANKX(
            FILTER('Table', 'Table'[Category] = "A"),
            'Table'[Volume],
            ,
            ASC,
            DENSE
        ) & "_" & 'Table'[User]
    ),
    "NewUser1", CALCULATE(
        MAX('Table'[AdjustedUser1]),
        ALLEXCEPT('Table', 'Table'[User])
    )
)

Then use the columns in the new table to create a bar chart.

 

Best Regards,
Zhu

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-linhuizh-msft
Community Support
Community Support

Thanks for the replies from parry2k.

 

Hi @jj304 ,

 

According to your description, I created simple data.

vlinhuizhmsft_0-1738748954333.png

 

When sorting this chart, it can only be sorted by one of the X-axis or Y-axis, if at the same time, you need the percentage to show the effect of descending, you can create a new calculated column that meets the descending order of the percentage, and use it as the Y-axis. The steps are as follows:

1. Create calculated columns:

 

AdjustedUser = IF('Table'[Category]="A",RANKX(FILTER('Table','Table'[Category]="A"),'Table'[Volume],,ASC,Dense)&"_"&'Table'[User])
NewUser = 
CALCULATE(MAX('Table'[AdjustedUser]),ALLEXCEPT('Table','Table'[User]))

 

vlinhuizhmsft_3-1738749539411.png

 

2. Use Newuser as the y-axis and sort by it:

vlinhuizhmsft_2-1738749442011.png

 

3. Comparison of results:

vlinhuizhmsft_4-1738749584483.png

Best Regards,
Zhu

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Hi @v-linhuizh-msft, thanks for your reply.  I am using Direct Query for this report so i cannot use this dax in a calculated columns.  When i try to use the dax in a measure it forces me to use some form of aggregration for the columns. 

Hi @jj304 ,

 

Since we can't use measure for y-axis, to achieve this sorting effect, I suggest you create a calculated table:

NewTable = ADDCOLUMNS(
    'Table',
    "AdjustedUser1", IF(
        'Table'[Category] = "A",
        RANKX(
            FILTER('Table', 'Table'[Category] = "A"),
            'Table'[Volume],
            ,
            ASC,
            DENSE
        ) & "_" & 'Table'[User]
    ),
    "NewUser1", CALCULATE(
        MAX('Table'[AdjustedUser1]),
        ALLEXCEPT('Table', 'Table'[User])
    )
)

Then use the columns in the new table to create a bar chart.

 

Best Regards,
Zhu

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

parry2k
Super User
Super User

@jj304 check the sort column by clicking the 3 dots on the visual.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@jj304 on the format pane, under layout, turn reverse order on and that will do it.

 

parry2k_0-1738681037320.png

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

jj304
Frequent Visitor

Hi @parry2k, thanks for your reply.  The reverse order reverses the ordering of bars but its still displaying by the legend (category) 

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors