Forum Discussion

matheus_peppers's avatar
matheus_peppers
Frequent Visitor
3 years ago
Solved

How to do multiple substitutions in the same step?

I am trying a challenge to do multiple substitutions in the same column, but only consume a single step, instead of having several.   Example:   I want to do the following substitutions in the co...
  • jbwtp's avatar
    jbwtp
    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