Forum Discussion
How to do multiple substitutions in the same step?
- 3 years ago
Well, the bits that you need above are:
translations = {{"instagram_stories", "stories"}, {"instream_stories", "instream stories"}, {"instream_video", "instream video"}, {"unknown", "desconhecido"}},This is a vocabulary of substitutions, what do you want to replace with what. You would need to add it manually (using Advanced Editor) between any lines (as long as it is not after the last one [before the last "in"). And of course you will need to add your pairs using the provided template/example above.
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",null,null,(x,y,z) as text => List.First(List.Select(translations, each _{0}=x)){1},{"Demo", "Demo - 2"})This line is what actually does the job, all you need to do here: change the #"Renamed Columns" to a reference to the step in your code that should preceed the replace.
Actually, I suggest that you would use the stock Replace command from menu on the columns that you want to replace values and then change the fourth parameter (Replacer.ReplaceText ) to (x,y,z) as text => List.First(List.Select(translations, each _{0}=x)){1} it should solve the problem.
Cheers,
John
Sorry buddy, I didn't understand it very well. Especially since I am very new to the M language. What would be the simplest way for me to do this? I tried to use List.ReplaceMatchingItems, but it didn't work. It says something like: "5 arguments have been entered for something that would expect 2 or 3 arguments". I don't get it, very well.
Well, the bits that you need above are:
translations = {{"instagram_stories", "stories"}, {"instream_stories", "instream stories"}, {"instream_video", "instream video"}, {"unknown", "desconhecido"}},
This is a vocabulary of substitutions, what do you want to replace with what. You would need to add it manually (using Advanced Editor) between any lines (as long as it is not after the last one [before the last "in"). And of course you will need to add your pairs using the provided template/example above.
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",null,null,(x,y,z) as text => List.First(List.Select(translations, each _{0}=x)){1},{"Demo", "Demo - 2"})
This line is what actually does the job, all you need to do here: change the #"Renamed Columns" to a reference to the step in your code that should preceed the replace.
Actually, I suggest that you would use the stock Replace command from menu on the columns that you want to replace values and then change the fourth parameter (Replacer.ReplaceText ) to (x,y,z) as text => List.First(List.Select(translations, each _{0}=x)){1} it should solve the problem.
Cheers,
John