Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
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
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
Solved! Go to 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.
Thanks for the replies from parry2k.
Hi @jj304 ,
According to your description, I created simple data.
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]))
2. Use Newuser as the y-axis and sort by it:
3. Comparison of results:
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.
@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.
@jj304 on the format pane, under layout, turn reverse order on and that will do it.
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.
Hi @parry2k, thanks for your reply. The reverse order reverses the ordering of bars but its still displaying by the legend (category)