Forum Discussion

ovetteabejuela's avatar
ovetteabejuela
Impactful Individual
9 years ago
Solved

Power Query | Batch Replace String

Hi,

 

How do I replace this:

Foreign Language 1Foreign Language 2Foreign Language 3Foreign Language 4Foreign Language 5Foreign Language 6

 

 

into this in a single pass:

In English 1In English 2In English 3In English 4In English 5In English 6

 

I can work with a table with an equivalent word in English for each foreign word but I'm just not sure how to do that in M.

 

[Edit]

 

Hi MarcelBeug,

 

Sorry to drag you into this but I think this is a piece of cake for you. =)

  • MarcelBeug's avatar
    MarcelBeug
    9 years ago

    In that case you can use this code:

     

    = Table.TransformColumnNames(Table1, each try Translations{[Foreign = _]}[English] otherwise _)

    It searches each column name in the Translations table and - if found - replaces it with English; if not found then leave it as is.

     

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ovetteabejuela..

     

    If the diferent texts are in a row first you have to select all these columns and unpivot using Unpivot Columns from Transform tab. In In this way you have only a column with the diferent texts.

     

    Then, You just select the column and to use "1-->2 Replace Values" from Transform tab.

     

     

     

    Tell us if this help you.

     

    Miltinho,

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi ovetteabejuela.

       

      I think you are complicating some easy to do with just using a merge query.

      Bye.

       

      Miltinho

    • ovetteabejuela's avatar
      ovetteabejuela
      Impactful Individual

      Hi Anonymous,

       

      Thank you for your input.

       

      Yes I was aware of the Replace Value method, however I was looking for something that works in a batch. So that if there are 10 words to replace I don't have to do 10 lines of Replace Values function.

      • ovetteabejuela's avatar
        ovetteabejuela
        Impactful Individual

        ok still!

         

        just about to apply the solution but I'm already at a halt because of this:

         

        Mine:

        let
        Source = Excel.Workbook(#"Sample File Parameter1", null, true),

         

        ImkeF's(in the comment section of the post)

        let
        Source = ReplacementsTable,

        ImKef started on the ReplacementsTable while I'm starting at my Raw data... hmmmm.... thinking... but could really use some help...