Showing results for 
Search instead for 
Did you mean: 
Regular Visitor

Trim transformation for list of columns



I'd like to execute the Trim transformation in Power Query for a set of columns in my table.

I can do that if I select manually by clicking on the columns one-by-one and once it's done I can do the transformation. However, I'd need to select loads of columns with similar names, so I'd rather give the list of these columns and execute the transformation for each.


This is the current syntax:
= Table.TransformColumns(
     PreviousStep, {
         { "Column1", Text.Trim, type text},
          "Column2", Text.Trim, type text},
          "Column5", Text.Trim, type text},
          "Column15", Text.Trim, type text},

Can we have something similar like this instead:
     PreviousStep, {
           {"Column1", "Column2", "Column5", "Column15"}, Text.Trim, type text })

Thanks in advance!

Community Support
Community Support

Hi @PDG_VL ,

Has your problem been solved, if so, please consider Accept a correct reply as the solution or share your own solution to help others find it.

Best Regards

Super User
Super User

Something like this?


    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclRQUNJRUnBSgNDOIDo2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Changed Columns" = Table.TransformColumns(#"Changed Type",{},Text.Trim)
    #"Changed Columns"

Thanks for the answer. It does this for all the columns in the previous steps, however, is there a way to select a list of columns and all (so let's say you have Column1, Column2, Column3 and only want to do this for Column1and2)?

So you called my bluff. Fair enough.


If this is important to you please consider raising it at

Helpful resources

September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Dev Camp Session 26

Check it Out!

Mark your calendars and join us on Thursday, September 29 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors