Forum Discussion
Rename a Column based on the Column Position
- 2 years ago
Hello,
There is an idea to solve your problem:
- Make the query capturing automatically the name of the first column
- Save it as variable
- Use this variable for the renaming
Let's say that we want to rename the first column of the following table by replacing the text '202400.xlsx' by 'Date'.
By doing it manually, Power BI will add the following step to the query, where the original column name is a fixed text.
We can replace this text by a variable that captures the first column name, which may change.
In this new query, the yellow line shows how can we get all the column names as a list with the function Table.ColumnNames, and the expression {0} to get the first item from the list (in that case, the first column name).
Then, in the last step, we can just replace the fixed text by this variable to make the query works in the same way, but able to update the name automatically even though the input files change.
Regards
Hello,
There is an idea to solve your problem:
- Make the query capturing automatically the name of the first column
- Save it as variable
- Use this variable for the renaming
Let's say that we want to rename the first column of the following table by replacing the text '202400.xlsx' by 'Date'.
By doing it manually, Power BI will add the following step to the query, where the original column name is a fixed text.
We can replace this text by a variable that captures the first column name, which may change.
In this new query, the yellow line shows how can we get all the column names as a list with the function Table.ColumnNames, and the expression {0} to get the first item from the list (in that case, the first column name).
Then, in the last step, we can just replace the fixed text by this variable to make the query works in the same way, but able to update the name automatically even though the input files change.
Regards
Hi, I'm not quite understanding how to enter this into the PowerBI
- Zang_Mi2 years agoResolver II
Hello, you can edit the query using Power Query Advanced Editor in Power BI.