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, Sorry for the long delays in replying. The first table shows and example of the main data, the 2nd the replacement data. As mentioned I have been able to get the results I wanted using:
= 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"})
as a step in power query, but it took a few reloads for it to really stick. I had to duplicate the step to replace values in both start and stop location.
| Driver Name | Start Location | Stop Location |
| 1 | Joe Bloggs | 19 Brownstone Ave, Cloverfield, SY89 4, UK | 50 One Rd, That Town, TV12 8, UK |
| 2 | Joe Bloggs | 50 One Rd, That Town, TV12 8, UK | Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5, UK |
| 3 | Joe Bloggs | Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5, UK | 70 Westview, PondTown, BV7 0, UK |
| 1 | Sarah Robbins | Location near BerryTree Lane, Maple, SK42 6, UK | Garage - Bradley Street, Tower Hill, WV8 4, UK |
| 2 | Sarah Robbins | Garage - Bradley Street, Tower Hill, WV8 4, UK | 11 Avalon Close, Cherryton, Warmly, BD76 2, UK |
| 3 | Sarah Robbins | 11 Avalon Close, Cherryton, Warmly, BD76 2, UK | Garage - Bradley Street, Tower Hill, WV8 4, UK |
| 4 | Sarah Robbins | Garage - Bradley Street, Tower Hill, WV8 4, UK | Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5, UK |
| 5 | Sarah Robbins | Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5, UK | Location near BerryTree Lane, Maple, SK42 6, UK |
| Current | Replace |
| Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5, UK | Skips - Long Rd (K3894), Sunny Side, By The River, BZ9 5GH, UK |
| Garage - Bradley Street, Tower Hill, WV8 4, UK | Garage - Bradley Street, Tower Hill, WV8 4HT, UK |
| Location near BerryTree Lane, Maple, SK42 6, UK | Newside near BerryTree Lane, Maple, SK42 6HT, UK |