Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello, everyone.
I have a question about how to use PowerQuery functions.
I want to give a rank as shown below.
How should I configure the function?
Solved! Go to Solution.
Hi @Minseok ,
Please put all of this M function into Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ30jcyMDJW0lHKLc7OzFWK1YlWMtU3xhQEqoMrRVJogC5mCFRljC5orm9oBhfLBQnGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [reg_date = _t, member_id = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"reg_date", type date}, {"member_id", type text}}),
#"GroupedRows" = Table.Group(#"Changed Type", {"member_id"}, {{"AllData", each _ ,type table}}),
#"SortedIndexedRows" = Table.TransformColumns(#"GroupedRows", {"AllData", (table) =>
let
SortedTable = Table.Sort(table, {{"reg_date", Order.Descending}}),
IndexedTable =
Table.AddIndexColumn(SortedTable, "RankOrder", 1, 1, Int64.Type)
in
IndexedTable
}),
#"ExpandedTable" =
Table.ExpandTableColumn(#"SortedIndexedRows", "AllData", {"reg_date", "member_id", "RankOrder"}, {"reg_date", "member_id1", "RankOrder"}),
#"Removed Columns" = Table.RemoveColumns(ExpandedTable,{"member_id1"})
in
#"Removed Columns"
The final output is as follow:
But if you need to implement sorting different ids separately, I suggest it might be more convenient to use DAX.
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Minseok ,
Please put all of this M function into Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ30jcyMDJW0lHKLc7OzFWK1YlWMtU3xhQEqoMrRVJogC5mCFRljC5orm9oBhfLBQnGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [reg_date = _t, member_id = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"reg_date", type date}, {"member_id", type text}}),
#"GroupedRows" = Table.Group(#"Changed Type", {"member_id"}, {{"AllData", each _ ,type table}}),
#"SortedIndexedRows" = Table.TransformColumns(#"GroupedRows", {"AllData", (table) =>
let
SortedTable = Table.Sort(table, {{"reg_date", Order.Descending}}),
IndexedTable =
Table.AddIndexColumn(SortedTable, "RankOrder", 1, 1, Int64.Type)
in
IndexedTable
}),
#"ExpandedTable" =
Table.ExpandTableColumn(#"SortedIndexedRows", "AllData", {"reg_date", "member_id", "RankOrder"}, {"reg_date", "member_id1", "RankOrder"}),
#"Removed Columns" = Table.RemoveColumns(ExpandedTable,{"member_id1"})
in
#"Removed Columns"
The final output is as follow:
But if you need to implement sorting different ids separately, I suggest it might be more convenient to use DAX.
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
How is the logic behind the Rank?
the 3rd row member on the right table does not have any same name but it ranks together with kim member
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |