Forum Discussion
Unable to Sort Stacked Bar Chart by Rank Measure Within X-Axis Hierarchy
- 1 year ago
Hi maryester ,
You're experiencing a common limitation in Power BI where it's not possible to sort bars within each subgroup on a stacked or combo column chart when using a hierarchy like "Year Month GI Date" > "Description" on the X-axis. Power BI only allows sorting by one level of the hierarchy at a time, so it either sorts by the top-level grouping (Year-Month) or the measure, but not within each group.
One workaround is to flatten the hierarchy by combining both fields into a single column, so each combination of Year-Month and Description becomes a unique axis value. You can create a calculated column like this:
CombinedAxis = FORMAT([Year Month GI Date], "YYYY-MM") & " - " & [Description]This removes the hierarchy and treats each value independently, allowing you to sort by the measure globally. However, it won't show grouped bars per month—it becomes a flat list.
If your goal is to preserve monthly grouping and still sort Descriptions within each month, a trickier workaround is to calculate a rank per month and append that rank to create a sorted axis. First, create a ranking measure:
DescriptionRank = RANKX( FILTER( ALLSELECTED('YourTable'), 'YourTable'[Year Month GI Date] = EARLIER('YourTable'[Year Month GI Date]) ), [Average of GI Date - Created on], , DESC )Then, create a sort key that combines the date, rank, and description:
SortKey = FORMAT([Year Month GI Date], "YYYY-MM") & "-" & FORMAT([DescriptionRank], "00") & "-" & [Description]SortKey = FORMAT([Year Month GI Date], "YYYY-MM") & "-" & FORMAT([DescriptionRank], "00") & "-" & [Description]
You can use this SortKey as your X-axis instead of the hierarchy and sort by this column. It visually preserves the grouping and sorts descriptions within each month, but you lose the drill-down functionality of the original hierarchy. For full sorting capabilities, the matrix visual remains the only one that supports sorting within groups properly.Best regards,
Hi maryester,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Thanks and regards
Hi, sorry for the late response.
I had to make some adjustments but yes, in the end, I was able to reach my goal.
Thank you, I will accept it as solution.
Mary