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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
eshetb
Frequent Visitor

can't sort a non-unique column based on another one

hey,

i'm trying to sort one column which has duplicate values by another one.

assume this example, where i want to have "status_category" sorted by "rank":

 

statusstatus categoryrank
newin progress10
first reviewin progress20
second reviewin progress30
rejectedclosed40
on holdhold50
closedclosed60
canceledclosed70

 

the problem is that one category value cannot have more than one rank value. (getting a can't sort error)
so i created another column, taking the min rank value for each category:

 

statusstatus_categoryrankmin_rank
newin progress1010
first reviewin progress2010
second reviewin progress3010
rejectedclosed4040
on holdhold5050
closedclosed6060
canceledclosed7060


using this:

 

min_rank = 
VAR currentCategory = table[status_category]
RETURN
    CALCULATE (
        MIN ( table[rank] ),
        FILTER ( ALL ( table), table[status_category] = currentCategory)
    )

so now there's only one possible rank for each category value.
however, wheb ttying the sort by option i get a new error: "This column can't be sorted by a column that is already sorted, directly or indirectly, by this column".
am i to understand that it's not possible to sort a column by another one that's calcaulated by it?

can anyone find a solution to either of the sort errors?

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

you can create the rank in query editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykstV9JRysxTKCjKTy9KLS4G8gwNlGJ1opXSMouKSxSKUssysagxgqgpTk3Oz0vBpcgYoqgoNSs1uSQ1BSiSnJNfDGaYQKTy8xQy8nNAAlDKFCIOVwdnmEElEvOSU3NQpcyBUrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [status = _t, #"status category" = _t, rank = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"status", type text}, {"status category", type text}, {"rank", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"status category", "rank"}),
    #"Grouped Rows" = Table.Group(#"Removed Other Columns", {"status category"}, {{"min_rank", each List.Min([rank]), type number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"status category"},#"Grouped Rows",{"status category"},"Custom1",JoinKind.LeftOuter),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Merged Queries", "Custom1", {"min_rank"}, {"min_rank"})
in
    #"Expanded Custom1"


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

2 REPLIES 2
Stachu
Community Champion
Community Champion

you can create the rank in query editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykstV9JRysxTKCjKTy9KLS4G8gwNlGJ1opXSMouKSxSKUssysagxgqgpTk3Oz0vBpcgYoqgoNSs1uSQ1BSiSnJNfDGaYQKTy8xQy8nNAAlDKFCIOVwdnmEElEvOSU3NQpcyBUrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [status = _t, #"status category" = _t, rank = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"status", type text}, {"status category", type text}, {"rank", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"status category", "rank"}),
    #"Grouped Rows" = Table.Group(#"Removed Other Columns", {"status category"}, {{"min_rank", each List.Min([rank]), type number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"status category"},#"Grouped Rows",{"status category"},"Custom1",JoinKind.LeftOuter),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Merged Queries", "Custom1", {"min_rank"}, {"min_rank"})
in
    #"Expanded Custom1"


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

eshetb
Frequent Visitor

Thanks, that's perfect!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.