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
obriaincian
Resolver I
Resolver I

Sort by column after grouping

Hi All,

 

 

I have a measure which calculates the percentage of missing data in a column.

I have added this measure to the bar chart below. 

X-Axis - Attribute

Y_Axis - Measure

Legend - Region

obriaincian_0-1741338912481.png

 

What I want is to sort the bars within the regions but I haven't been able to do it 

 

My Measure (Note the measure does perform some filters in the calcs that I left out, That's why it looks repetitive)

 

Missing Data % =
VAR TotalRows = COUNTROWS('Data')
RETURN
SWITCH(
    TRUE(),
    SELECTEDVALUE('Data'[Attribute]) = "Attribute 1",
        DIVIDE(
            CALCULATE(COUNTROWS('Data'), 'Data'[Value] = "Attribute 2"),
            TotalRows),

     SELECTEDVALUE('Data'[Attribute]) = "Attribute 2",
        DIVIDE(
            CALCULATE(COUNTROWS('Data'), 'Data'[Value] = "Attribute 2"),
            TotalRows),

    SELECTEDVALUE('Data'[Attribute]) = "Attribute 3",
        DIVIDE(
            CALCULATE(COUNTROWS('Data'), 'Data'[Value] = "No Value"),
            TotalRows),

    SELECTEDVALUE('Data'[Attribute]) = "Attribute 4",
        CALCULATE(DIVIDE(
            CALCULATE(COUNTROWS('Data'), 'Data'[Value] = "No Value"),
            TotalRows2)),

    SELECTEDVALUE('Data'[Attribute]) = "Attribute 5",
        DIVIDE(
            CALCULATE(COUNTROWS('Data'), 'Data'[Value] = "No Value"),
            TotalRows),

    0  // Default return value if none of the conditions are met
)

 

 

 

Can someone tell me how I can sort the bars withint each region?, I don't want to create a calculated table either as I have several filters on the page that need to be functional

7 REPLIES 7
v-kpoloju-msft
Community Support
Community Support

Hi @obriaincian,

May i know has your issue been resolved? If the response provided by the @danextian@sanalytics@DataNinja777, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

 

If yes, kindly accept the useful reply as a solution and give us Kudos. It would be appreciated.

Thank you for your understanding!

Hi @obriaincian,


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 my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


Thank you.

Hi @obriaincian,

I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

danextian
Super User
Super User

Hi @obriaincian

 

Sorting the legends by the value within a specific category currently isn't supported. There are workarounds but they aren't perefect. In the screenshot below, Geo column is ranked by Total Revenue. The ranks are then materialized using a disconnected table and then a  column from that disconnected table is used in the visual.

danextian_0-1741360917456.png

The second chart uses small multiples.

 

Please see the attached sample pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
sanalytics
Super User
Super User

Hello @obriaincian 
If you dont have any specific sort criteria the go to the 3 dot of the visual and go to sort the legend option. Below screenshot

sanalytics_0-1741340148539.png

if you have any specific sorting condition then go to Power query or your data source and add a sorting column. Use that column for region sorting. Just like below screenshot

sanalytics_1-1741340234642.png

Hope it helps

 

Regards

sanalytics

 

@sanalytics you are sorting by region, this is not what I want. I want to sort by the bars within each of the regions

DataNinja777
Super User
Super User

Hi @obriaincian ,

 

Power BI does not allow you to re-sort each region’s bars independently when they share the same X-axis. The chart treats the Attribute field as one set of categories and applies a single sort rule across them (alphabetical or by a single measure). A typical workaround is to use small multiples, where each region becomes its own mini-chart and you can independently sort by “Missing Data %.” For example, you could add a rank measure like “Rank Attribute = RANKX(ALL('Data'[Attribute]), [Missing Data %], [Missing Data %], DESC)” and then sort each small multiple by this rank measure. Another option is to create a separate visual for each region, then filter the chart to that region and sort by your measure. If you need one single global order (rather than different orders per region), you can create a custom column to specify a sort index, then use “Sort by Column” on that column to define the order of your attributes.

 

Best regards,

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.