Forum Discussion
Function to update any table with new values from another table
Hi freelensia & thowa ,
not sure about the performance on 100s of 1000s rows - Table.Group may be a bit heavy on large datasets, - but this is a function to do what you want (using thowa's data as an example):
(Dictionary as table, Update as table, Attributes as list)=>
let
AttributeFields = Attributes,
ValueFields = List.RemoveItems(Table.ColumnNames(Source), AttributeFields),
ValueFieldFunction = List.Accumulate(ValueFields, {}, (a, n) => a & {{n, (x)=>List.First(List.RemoveNulls(Table.Column(x, n)))}}),
Source = Table.Combine({Update, Dictionary}),
#"Grouped Rows" = Table.Group(Source, AttributeFields, ValueFieldFunction)
in
#"Grouped Rows"
Update parameter is the one that takes precedent on changed data (i.e. assumed table 1 in thowa's example).
This relies on the fact that you can direct PQ to put one table "on top" of another when appending.
Attributes parameter takes the "group by" list - a list of fields that you want to match by.
The output needs to the post-processed as the function removes types and shuffle the columns.
Kind regards,
JB
Works fine!
An other alternative approach was posted here:
Overlaying/merging two tables to add missing data in empty cells and new rows/columns
By camargos88
Thanks to both oof you!