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
maryester
New Member

Unable to Sort Stacked Bar Chart by Rank Measure Within X-Axis Hierarchy

Hello everyone,

I'm encountering an issue with sorting a stacked bar chart in Power BI Desktop and I'm hoping someone can help me understand if there's a solution or if I'm running into a limitation.

 

I have a line and stacked column combo chart visualizing the average of "GI Date - Created on" (number of days) for different "Description" (clusters) values within each "Year Month GI Date". The X-axis has a hierarchy with "Year Month GI Date" (year and month" as the top level and "Description" as the bottom level. The Y-axis shows the average of "GI Date - Created on", and I also have two lines using the secondary Y-axis ("Pcs/Tasks Picking" and "Sum of Qty Picking").

Goal:

I would like to sort the bars ("Description") within each "Year Month GI Date" in descending order based on the "Average of GI Date - Created on" value.
It seems I can only sort either by "Year Month Gi Date" or by average of "Gi Date-Created on".

Thanks
Mary


1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

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,

 

View solution in original post

6 REPLIES 6
v-nmadadi-msft
Community Support
Community Support

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

v-nmadadi-msft
Community Support
Community Support

Hi @maryester 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If our responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


Thank you.

v-nmadadi-msft
Community Support
Community Support

Hi @maryester,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

maryester
New Member

Hi @DataNinja777,
thank you so much for your explanation and for your suggestions, I will try to create the raniking measure.

Thank you again,
Mary

DataNinja777
Super User
Super User

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,

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.