The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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)