Forum Discussion
Ian Bruckner
Dec 05, 2018Iron Contributor
Replace values in a given column (column is comma separated id's) with lookupvalue from a query
How can I replace the values in this first column
With the lookup value from this other query? Ideally it comma separates the values, skipping anything that's null in the lookup (so no blank spaces between commas.
7 Replies
- Ian BrucknerIron Contributor
Imke Feldmann - I wonder if you have a suggestion :) ?
- SergeiBaklanDiamond Contributor
Hi Ian,
If I understood you correctly the transformation is like this
If so, the script could be
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], TextsToLists = Table.AddColumn(Source, "Custom", each Text.SplitAny([col],",")), AddIndex = Table.AddIndexColumn(TextsToLists, "Index", 0, 1), ListsToRows = Table.ExpandListColumn(AddIndex, "Custom"), IDasNumber = Table.TransformColumnTypes(ListsToRows,{{"Custom", Int64.Type}}), MergeWithLookupTable = Table.NestedJoin(IDasNumber,{"Custom"},Table2,{"ID"},"Table2",JoinKind.LeftOuter), GetValues = Table.ExpandTableColumn(MergeWithLookupTable, "Table2", {"Value"}, {"Value"}), GroupByIndex = Table.Group(GetValues, {"Index"}, {{"Count", each _, type table}}), ValuesToCSV = Table.AddColumn(GroupByIndex, "Custom", each Text.Combine(GroupByIndex[Count]{[Index]}[Value],",")), RemoveUnused = Table.SelectColumns(ValuesToCSV,{"Custom"}) in RemoveUnused
Please see attached
- kalyanpolasiCopper Contributorcan you please tell where to write this script. I have the same exact requirement. Trying to understand what script is this and how to execute? Please advise