Forum Discussion
E_K_
Helper III
4 years agoPower Query - Replace multiple substrings in one list column
I am trying to do this for a column where the are text values listed in all sorts of ways, with comma as delimiter. Eg Old value New value ALE, AEX, DDI, ELV, PRT, ZAI, ZZI Allegro, Aero...
- 4 years ago
One way:
- Create a two column replacement table
- I named the columns "LookFor" and "Replace"
Then you can use code like below in your 'Main Query'
//create a Replacement List from the Replacement Table #"Replacement List"=List.Zip({Replacements[LookFor],Replacements[Replace]}), //Do the actual replacements using the TransformColumns method #"Replace Multiple" = Table.TransformColumns(#"Previous Step", {"Column1", (s)=> Text.Combine( List.ReplaceMatchingItems( List.Transform(Text.Split(s,","), Text.Trim), #"Replacement List"), ",") }) in #"Replace Multiple" - Create a two column replacement table
Vijay_A_Verma
Most Valuable Professional
4 years agoNeed some clarity on this requirement. If it is a matter of replace A with Aa and so on, it is very easy. But I believe this example is not right as in below code, you are replacing TRACY with TRACI and so on.
I would like to know that do you have a mapping table / list where I know TRACY has to be replaced with TRACI OR Y with I.....If yes, can you post this mapping table here?