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
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)
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.