Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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

4 REPLIES 4
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.