Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I have a table with Sales orders. I want in PowerQuery or with a SQL in a view in Lakehouse, to fill in the same PO number in the fields that doesn't have a sales order, so if this is my data:
SalesOrder | Item | PO |
7513 | 1 | # |
7513 | 2 | 7899 |
7513 | 3 | # |
7535 | 1 | # |
7535 | 2 | # |
7535 | 3 | # |
7535 | 4 | # |
8674 | 1 | # |
8674 | 2 | # |
8674 | 3 | # |
8674 | 4 | 6541 |
Then it should look like this:
SalesOrder | Item | PO |
7513 | 1 | 7899 |
7513 | 2 | 7899 |
7513 | 3 | 7899 |
7535 | 1 | # |
7535 | 2 | # |
7535 | 3 | # |
7535 | 4 | # |
8674 | 1 | 6541 |
8674 | 2 | 6541 |
8674 | 3 | 6541 |
8674 | 4 | 6541 |
Solved! Go to Solution.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjc1NFbSUTIEYmWlWB24gBEQm1tYWiKLGSMpMjZF0wUWMEIXwNBiAhewMDM3QTEDKmCELmCMLgDCZqYmhkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SalesOrder = _t, Item = _t, PO = _t]),
#"Grouped Rows" = Table.Group(Source, {"SalesOrder"}, {{"Rows", each _, type table [SalesOrder=nullable text, Item=nullable text, PO=nullable text]}, {"PO", each List.Max([PO]), type nullable text}}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Item"}, {"Item"})
in
#"Expanded Rows"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjc1NFbSUTIEYmWlWB24gBEQm1tYWiKLGSMpMjZF0wUWMEIXwNBiAhewMDM3QTEDKmCELmCMLgDCZqYmhkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SalesOrder = _t, Item = _t, PO = _t]),
#"Grouped Rows" = Table.Group(Source, {"SalesOrder"}, {{"Rows", each _, type table [SalesOrder=nullable text, Item=nullable text, PO=nullable text]}, {"PO", each List.Max([PO]), type nullable text}}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Item"}, {"Item"})
in
#"Expanded Rows"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.
I have 10. million rows of data. Is there a more efficient way to do this or is this the best solution?
I would say this is the best you can do in Power Query. You can try to add a Table.Buffer but it may not help (or even make things slower)
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
24 | |
13 | |
12 | |
11 | |
8 |
User | Count |
---|---|
42 | |
25 | |
14 | |
14 | |
12 |