March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi All,
I've run into a weird problem: when I create stacked bar chart and sort it by total value, when then total values are the same, the visual gives preference to the bar where there are more yellow values than red. The business requirement is to make it vice versa.
I've added a sort column to the column which is in the legend bucket, tried it both ways (red 1 yellow 2, red 2 yellow 1), it is still the same.
Funnily enough, if I sort it ascending , it works as I expect it (5 is below 3), so it makes me think that this order is random.
Any ideas? Is there a way to add this secondary sorting criteria?
Solved! Go to Solution.
Hi @itskool
I have a solution, it is a bit wonky but seems to work nonetheless.
Assuming you have data that looks something like this:
And you create a chart based on this table, where Item is the Y-axis, Sum of Value is the X-axis, and Color is the Legend.
SortOrderHelper =
VAR curritem = Sorting[Item]
VAR totVal = CALCULATE(SUM('Table'[Value]),'Table'[Item]=curritem)
VAR redVal = CALCULATE(SUM('Table'[Value]),'Table'[Item]=curritem, 'Table'[Color]="Red")
RETURN
totVal+(redVal/100)
Sort axis by Max of SortOrder, and it should get you the correct sorting with red being prioritised for tiebreaks.
Note: Depending on your data, the division by 100 might not be sufficient (if you have 100+ red values for an item, it might mess up the order completely). You can change it to a higher number, or create a VAR that calculates the largest red value dynamically, add +1 to that and divide by that amount (this is so you never have a redVal fraction that is > 1).
Also make sure that the calculated columns you create are formatted as decimal numbers, with enough decimals to show the difference in the tiebreaks.
I hope this helps, let me know if you have any questions.
Proud to be a Super User! | |
"➨Please mark the relevant answer it it helped you so that it can help others too
∎ Help the community back!
Hi @itskool
I have a solution, it is a bit wonky but seems to work nonetheless.
Assuming you have data that looks something like this:
And you create a chart based on this table, where Item is the Y-axis, Sum of Value is the X-axis, and Color is the Legend.
SortOrderHelper =
VAR curritem = Sorting[Item]
VAR totVal = CALCULATE(SUM('Table'[Value]),'Table'[Item]=curritem)
VAR redVal = CALCULATE(SUM('Table'[Value]),'Table'[Item]=curritem, 'Table'[Color]="Red")
RETURN
totVal+(redVal/100)
Sort axis by Max of SortOrder, and it should get you the correct sorting with red being prioritised for tiebreaks.
Note: Depending on your data, the division by 100 might not be sufficient (if you have 100+ red values for an item, it might mess up the order completely). You can change it to a higher number, or create a VAR that calculates the largest red value dynamically, add +1 to that and divide by that amount (this is so you never have a redVal fraction that is > 1).
Also make sure that the calculated columns you create are formatted as decimal numbers, with enough decimals to show the difference in the tiebreaks.
I hope this helps, let me know if you have any questions.
Proud to be a Super User! | |
hi @itskool
The game here is to reverse the alphabetical order of the Legend
"f" comes first, hence it is on the LHS
I wrote a calculation and bring the same to legend and I was able to reverse it
Regards,
Ritesh
"➨Please mark the answer it it helped you so that it can help others too
∎ My You tube Channel Dance-Sing with Data Projects - YouTube"
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
114 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
168 | |
116 | |
63 | |
57 | |
50 |