Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Rename some columns by adding a prefix

Hi everyone.

I have some tables with aprox. 40 columns. I would like to rename some of these columns by adding a prefix. I have tried Table.PrefixColumns but this adds a prefix to all the columns. Is there a way to achieve this only in some columns?

 

Thanks a lot

 

7 Replies

    1. Create a list of the columns you want to prefix
    2.  List.Transform => create a "Rename List".
    3.  Table.RenameColumns

    Code Example:

    let
        tbl = Table.FromColumns(
            {{"a","B","C","D","E"},
            {"F","G","H","I","J"},
            {"K","L","M","N","O","P"},
            {"Q","R","S","T","U"},
            {"F","G","H","I","J"},
            {"K","L","M","N","O","P"}}
            ),
       
        #"Columns to Prefix" = {"Column2", "Column4", "Column6"},
        Prefix = "Old.",
        Renames = List.Transform(#"Columns to Prefix", each {_, Prefix & _}),
    
        #"Prefix Some" = Table.RenameColumns(tbl, Renames)
    in 
        #"Prefix Some"

    Before

     

    After

     

     

  • KNP's avatar
    KNP
    Super User

    Probably, which columns?

    Please provide sample data.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, basically I want to achieve this:

      All columns but ITEM, get the prefix "CANT" in their name

  • Anonymous's avatar
    Anonymous
    Not applicable

    Guys, you are awesome.