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

Get 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

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
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.