Forum Discussion
Replacing values in one column with values from another table
- 4 years ago
Hi, Anonymous
Check whether the above search column text contains invisible characters. The simple way to avoid this error is to copy and paste the column name.
refer:
Table.ReplaceValue
Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table
Here is a solution I thought of, which may help you.
I encapsulated a function that replaces the value, which can be called on the column. This works for all columns.
Create a blank query, open Advanced Editor and replace the text there with the code below. In your original query, you can then go to the Add Column tab, invoke custom function and choose this function and choose your "Old" column as the input.(inputtext as text) => let Result = List.ReplaceMatchingItems(Table.ToList(Table.FromValue(Text.From(inputtext))), List.Zip({Amendments[Current], Amendments[Replace]})) in Result{0}Result:
Please refer to the attachment below for details. Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sometimes it's easier to break this down into multiple steps rather than trying to do it all at once.
See attached PBIX file for a very basic example of what I mean.
It essentially merges the "lookup" table (called mapping in my case) with a left join and then uses the new value if not null otherwise uses the original.
You can then just remove the columns you don't need.
Don't forget, Power Query is case sensitive, so you will need to account for that if this is an issue.
I hope this helps.
- Anonymous4 years agoNot applicable
Thanks you KNP , this is a good solution. I really wanted to try to find a way to replace without adding anotnher column, which I have done using the orginal code, the missue seems to be around the placement of the step. Thank you for responding though, this is no doubt be a useful addition to my tool kit!