Jason
Jason

Reputation: 21

Insert current date in column name

I'm starting to use Power Query in Excel 365 (desktop install). Is there a way to change the column name to append or prepend today's date to the column name? If the column is named "Size" I'd like the column to be named "Size_2019_04_18". The exact format of the date doesn't matter.

Upvotes: 1

Views: 1156

Answers (1)

Gen Wan
Gen Wan

Reputation: 2019

1, Go to Power Query Editor

2, Go to Advanced Editor

enter image description here

3, add the code below (Case Sentitive):

Let
   ...
   NewName = "Size_"&Date.ToText(DateTime.Date(DateTime.LocalNow())),
   #"Changed Type" = Table.TransformColumnTypes(Sheet1_Table,{{"Size", Int64.Type}}),
   #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Size", NewName}})

in
   #"Renamed Columns"

Test Result: enter image description here

Upvotes: 2

Related Questions