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.
Asked
Active
Viewed 782 times
1
-
i don't know about Power Query, but VBA can do this pretty easily. – John Lord Apr 18 '19 at 20:02
1 Answers
2
1, Go to Power Query Editor
2, Go to Advanced Editor
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"

Gen Wan
- 1,979
- 2
- 12
- 19
-
Follow-up question to this. Whenever the data is refreshed now the date changes to the current date, which makes sense. Is there a way using Power Query to make the date stick after it is applied? I don't want it refreshed after the initial calculation. So if it gets set to 5/6/2019 on 5/6, when I refresh the data on 5/8 it's changing to 5/8/2019. I would like it to stay at 5/6/2019. – Jason May 08 '19 at 18:11
-
@Jason This is a different question. You want to keep the first occurrence since the column name is changing by time, am I right? Please ask one question separately. – Gen Wan May 08 '19 at 18:23
-
Thanks for replaying. I did create a new question. [link] (https://stackoverflow.com/questions/56084559/having-values-persist-in-column-names) – Jason May 10 '19 at 20:39