Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
PDG_VL
Helper I
Helper I

Trim transformation for list of columns

Hi,

 

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:
Table.TransformColumns(
     PreviousStep, {
           {"Column1", "Column2", "Column5", "Column15"}, Text.Trim, type text })

Thanks in advance!

4 REPLIES 4
v-luwang-msft
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
Lucien

lbendlin
Super User
Super User

Something like this?

 

let
    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)
in
    #"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 https://ideas.powerbi.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.