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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
pbakaric
Frequent Visitor

Stacked bar chart won't sort properly with value in legend

I'm having an issue with the stacked bar chart. If I insert a value for the legend, then the chart will not sort properly when I select "sort by" from the graphic menu. It seems like the sort does not take into account the impact of the legend value. This seems like this might be a bug? Let me emphasize, I did select "sort by" multiple times but it never orders properly. I expect to Pareto both bar charts (in order of largest to smallest value).

 

No legend value:

No legend value.JPG

 

 

With legend value:

With legend value.JPG

 

Datasets:

 

Volume DataVolume DataDefect DataDefect Data

Dataset Relationship:

Dataset Relationship.JPG

 

Yield Contributor formula:

Yield Contributor = DIVIDE(SUM(Defect[Count]),SUM(Volume[Count]))

8 REPLIES 8
freyadudding2
Frequent Visitor

I actually found a solution!

 

I created a measure that did
CALCULATE(measure, Type = A) + CALCULATE(measure, Type = B) + CALCULATE(measure, Type = C)
Then I added this to the tooltip and sorted by this instead

freyadudding2
Frequent Visitor

Only 7 years later but I am having this same issue and cannot find another post to help me find a solution to this! Does anyone know why using a measure and a legend in stacked bar ruins the sort order?!

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @pbakaric,

 

Below is the result in my test, as you can see, the appearance of bar chart and the sequence of sort by are not affected by legend. Also, it is only allowed to sort the chart based on the columns added to Axis and Value, that is to say we cannot sort by legend.

3.PNG

 

From the two images you post, it seems that the value on X-axis is changed after adding legend. Are the source data the same in these two charts? What do you mean "the sort does not take into account the impact of the legend value"? It is not clear about how you want to sort the chart? Would you please provide more detaied description about your expect result, if possible you can upload your pbix file.

 

Thanks,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Yuliana,

 

Thank you for the response. How do I upload a file? I don't see an option to add a file. I have created a simplified example to share. I have also updated my original post with that example. 

 

To quickly address your questions:

1) Yes, the data source is the same in both charts.

2) I expect to show the graphic as a Pareto (order values from largest to smallest)

 

Hi @pbakaric,

 

Remove the relationship between these two tables.

5.PNG

 

If you still have any question, please feel free to ask.

 

Thanks,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Yuliana,

 

The relationship is important and cannot be removed. Your calculated values are not correct with the relationship removed.

 

 

Why can the sort not take into account the impact of the legend? The sort order should be determined by the total value for each item. 

 

Preston

@pbakaric

 

I am able to sort the chart after adding the legends too. 

 

 Capture1.PNGCapture.PNG

Thiyags,

You are not using the measure I listed above called "yield contributor". The calculation makes the defect count more impactful with the lower volume count of C. Your example is not the same and will not show the issue.

Preston

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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