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.
Hi smpa01 , I can't figure out how to attached a pbix here. What I have found is that
= Table.ReplaceValue ( #"Changed Type",each [Stop Location], each List.Accumulate (List.Buffer(Table.ToRecords(Amendments)),[Stop Location], (valueToReplace, replaceOldNewRecord)=>Text.Replace (valueToReplace, replaceOldNewRecord[Current], replaceOldNewRecord[Replace])),Replacer.ReplaceText,{"Stop Location"})
Does actually work, the issue was where I had the step. I moved it so that it was directly after promoting first row to headers and prior to a data change and it worked. I added a second step, the same as above to amend the start locations also.
For some reason I had to refresh about 3 times for everything to 'stick' I have no idea why this might be.
- smpa014 years agoCommunity Champion
Anonymous you can easily copy paste sample data and desired output here. If you fail, you can always uplaod a sample pbix in g/1 drive and share the linke here. Without sample data I can't advise.