Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
MegaOctane1
Helper I
Helper I

Fill in missing values for all items in sales order if one item has value

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:

SalesOrderItemPO
75131#
751327899
75133#
75351#
75352#
75353#
75354#
86741#
86742#
86743#
867446541

 

Then it should look like this:

SalesOrderItemPO
751317899
751327899
751337899
75351#
75352#
75353#
75354#
867416541
867426541
867436541
867446541
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

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)

Thanks @lbendlin,
Works like a charm. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors