- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

rank in powerquery with criteria
Hi everybody, I've been facing problem to create a rank in PowerQuery (m-language) with criteria.
Could you help me?
Table1
Data | Unit | Sku | Qty | Rank |
2021-02-01 | New York | 100500 | 100.5 | |
2021-02-01 | New York | 100600 | 95.0 | |
2021-02-01 | New York | 100700 | 90.0 | |
2021-02-01 | Los Angeles | 100500 | 110.5 | |
2021-02-01 | Los Angeles | 100600 | 100.0 | |
2021-02-01 | Los Angeles | 100700 | 50.0 |
Expected table
Data | Unit | Sku | Qty | Rank |
2021-02-01 | New York | 100500 | 100.5 | 1 |
2021-02-01 | New York | 100600 | 95.0 | 2 |
2021-02-01 | New York | 100700 | 90.0 | 3 |
2021-02-01 | Los Angeles | 100500 | 110.5 | 1 |
2021-02-01 | Los Angeles | 100600 | 100.0 | 2 |
2021-02-01 | Los Angeles | 100700 | 50.0 | 3 |
Thanks in advanced.
William M.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @William_Moreno ,
1. Open the Advanced Editor and place the following code.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ1MNI1MFTSUfJLLVeIzC/KBjINDQxMDQwgDD1TpVgdvErNwEotTfUMCKk0h6g0wKbSJ79YwTEvPTUntRjFBYZYXYCh2gzuXmLMhjjEFKw4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, Unit = _t, Sku = _t, Qty = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"Unit", type text}, {"Sku", Int64.Type}, {"Qty", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Unit"}, {{"flag", each _, type table [Data=nullable date, Unit=nullable text, Sku=nullable number, Qty=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([flag],"Index",1,1)),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Data", "Unit", "Sku", "Qty", "Index"}, {"Custom.Data", "Custom.Unit", "Custom.Sku", "Custom.Qty", "Custom.Index"})
in
#"Expanded Custom"
2. Result.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @William_Moreno ,
1. Open the Advanced Editor and place the following code.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ1MNI1MFTSUfJLLVeIzC/KBjINDQxMDQwgDD1TpVgdvErNwEotTfUMCKk0h6g0wKbSJ79YwTEvPTUntRjFBYZYXYCh2gzuXmLMhjjEFKw4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, Unit = _t, Sku = _t, Qty = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"Unit", type text}, {"Sku", Int64.Type}, {"Qty", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Unit"}, {{"flag", each _, type table [Data=nullable date, Unit=nullable text, Sku=nullable number, Qty=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([flag],"Index",1,1)),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Data", "Unit", "Sku", "Qty", "Index"}, {"Custom.Data", "Custom.Unit", "Custom.Sku", "Custom.Qty", "Custom.Index"})
in
#"Expanded Custom"
2. Result.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@William_Moreno , I think this video from Curbal can help. - Add index to subgroups in Power Query

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
12-06-2024 08:13 AM | |||
12-21-2024 08:32 PM | |||
Anonymous
| 06-09-2020 02:43 AM | ||
01-12-2025 09:31 AM | |||
12-03-2024 01:00 AM |
User | Count |
---|---|
132 | |
105 | |
85 | |
55 | |
46 |