Forum Discussion
Getting the date from the file name in PowerQuery
- 4 years ago
Hi IEG
Is this column always at the same position in different files? If so, you can change its column name based on position.
For example, there are 4 columns in below table.
Table.ColumnNames function will get back all column names in a table. It returns a list of names, so the index starts from 0. You can use Table.ColumnNames(#"previous step name"){0} to get the name of the first column. If the column you want to rename is the fifth column, you just need to change 0 to 4.
Then when you rename a column, you can use
= Table.RenameColumns(#"Changed Type",{{Table.ColumnNames(#"Changed Type"){4}, "new column name"}})Based on BA_Pete 's solution, you already get the date from file name, so you can add a custom step after that.
= Table.RenameColumns(#"Changed Type",{{Table.ColumnNames(#"Changed Type"){4}, Table.Column(#"Changed Type", "Name"){0}}})Renaming A Column In Power Query Based On Position — ehansalytics
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Thanks Pete, however I am lost at some point. This will give me table with my data and a column with a date in it. I want to change the header of the column according to that date, how can I use this column to do that?
Hi IEG
Is this column always at the same position in different files? If so, you can change its column name based on position.
For example, there are 4 columns in below table.
Table.ColumnNames function will get back all column names in a table. It returns a list of names, so the index starts from 0. You can use Table.ColumnNames(#"previous step name"){0} to get the name of the first column. If the column you want to rename is the fifth column, you just need to change 0 to 4.
Then when you rename a column, you can use
= Table.RenameColumns(#"Changed Type",{{Table.ColumnNames(#"Changed Type"){4}, "new column name"}})
Based on BA_Pete 's solution, you already get the date from file name, so you can add a custom step after that.
= Table.RenameColumns(#"Changed Type",{{Table.ColumnNames(#"Changed Type"){4}, Table.Column(#"Changed Type", "Name"){0}}})
Renaming A Column In Power Query Based On Position — ehansalytics
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.