Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How to update a column name when data is refreshed

I have a power query where I use two blank query's to add two columns based on the data in first column. = (YourWorkSheet as table ) as text=> let SheetCellA1 =YourWorkSheet[Column1]{0}, S...
  • PhilipTreacy's avatar
    5 years ago

    Hi Anonymous 

    If the columns you want to rename will always be the 1st and 2nd ones, you can reference the columns by their index (indexed from 0)

     

     

    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{Table.ColumnNames(#"Promoted Headers"){0}, "TIME"}, {Table.ColumnNames(#"Promoted Headers"){1}, "MARKET"}, {"Column3", "SEGMENT"}, {"Column4", "SUB-SEGMENT"}, {"Column5", "UPC"}, {"Column6", "DESCRIPTION"}, {"Column7", "SIZE"}, {"Column8", "FLAVOR"}, {"Column9", "BRAND"}})

     

     

    Phil 


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.

  • PhilipTreacy's avatar
    PhilipTreacy
    5 years ago

    Anonymous 

    No these 2 lines are not needed

     

    DynamicNameHeader= Table.ColumnNames(#"Promoted Headers"){0},
    DynmaicNameHeader.1= Table.ColumnNames(#"Promoted Headers"){1},

     

    All they do is assign the names of the first 2 columns to variables.  But these variables are not used in the subsequent  Table.RenameColumns

     

    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{Table.ColumnNames(#"Promoted Headers"){0}, "TIME"}, {Table.ColumnNames(#"Promoted Headers"){1}, "MARKET"}, {"Column3", "SEGMENT"}, {"Column4", "SUB-SEGMENT"}, {"Column5", "UPC"}, {"Column6", "DESCRIPTION"}, {"Column7", "SIZE"}, {"Column8", "FLAVOR"}, {"Column9", "BRAND"}})

     

     Phil


    If I answered your question please mark my post as the solution.
    If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.