March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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":
status | status category | rank |
new | in progress | 10 |
first review | in progress | 20 |
second review | in progress | 30 |
rejected | closed | 40 |
on hold | hold | 50 |
closed | closed | 60 |
canceled | closed | 70 |
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:
status | status_category | rank | min_rank |
new | in progress | 10 | 10 |
first review | in progress | 20 | 10 |
second review | in progress | 30 | 10 |
rejected | closed | 40 | 40 |
on hold | hold | 50 | 50 |
closed | closed | 60 | 60 |
canceled | closed | 70 | 60 |
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?
Solved! Go to Solution.
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"
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"
Thanks, that's perfect!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |