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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
markmess77
Resolver I
Resolver I

Issue with sorting column by index

I want to display a stacked bar chart with categories in a custom order with a tooltip showing the percentage of total of each category in the bar. It seems I am able to do one, but not both. The measure used to display the percent of total is below:

Measure = 
DIVIDE (
    DISTINCTCOUNT(Table[ID]),
    CALCULATE(DISTINCTCOUNT(Table[ID]), ALL(Workflows[Category]) ),
    0
) 

This measure works perfectly fine. 

I am also trying to display the categories in a custom order by index. However, when I go to the Data tab and sort the Category field by the index - while it sorts the categories in the correct order, the % of total of each category in the stacked bar now all evaluate to 100%. If I revert to sorting the the categories field in the default manner, the % of total works fine again.

Any ideas how to fix this issue?

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @markmess77 ,

 

when you are using a sort-by-column, you also have to add this column with an ALL. The reason is that in the background there is a group by the sort column. Check the following article if you fully want to understand the problem:

Side effects of the Sort By Column setting in DAX - SQLBI

 

Otherwise you can just add the sort by column:

Measure = 
DIVIDE (
    DISTINCTCOUNT(Table[ID]),
    CALCULATE(DISTINCTCOUNT(Table[ID]), ALL(Workflows[Category]), ALL(Workflows[CategorySortByColumn]) ),
    0
) 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

1 REPLY 1
selimovd
Super User
Super User

Hey @markmess77 ,

 

when you are using a sort-by-column, you also have to add this column with an ALL. The reason is that in the background there is a group by the sort column. Check the following article if you fully want to understand the problem:

Side effects of the Sort By Column setting in DAX - SQLBI

 

Otherwise you can just add the sort by column:

Measure = 
DIVIDE (
    DISTINCTCOUNT(Table[ID]),
    CALCULATE(DISTINCTCOUNT(Table[ID]), ALL(Workflows[Category]), ALL(Workflows[CategorySortByColumn]) ),
    0
) 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors