Forum Discussion
Dynamic column name from its value
- 9 years ago
Watch this video in which "Source" is the name of the previous step in my query.
Unfortunately, while typing, it jumped from the second line to the first line, but it is the same "Source".
The easiest way is to create some base code in M by double clicking the column header and change the name in just something.
Then adjust the generated code, like:
= Table.RenameColumns(Dimension,{{"Dimension_Name", Dimension[Dimension_Name]{0}}})
In this code "Dimension" is the name of your previous step in the code. If that is something else then you must use that step, e.g. if it would have been #"Changed Type", then:
= Table.RenameColumns(#"Changed Type",{{"Dimension_Name", #"Changed Type"[Dimension_Name]{0}}})The first #"Changed Type" is generated automatically, so you need to use this name in the adjusted formula.
- pager9 years agoFrequent Visitor
Hi Marcel,
I am also trying to do this for my report and am trying to follow along your explanation.
Can you clarify on "Dimension" being the previous step of the code? Looking at your first code in your reply, it looks like "Dimension" is the table in which the data is being pulled.
Also, can you elaborate on the "#changed type"? Not sure what how that would be generated automatically.
Thanks for your help!
- MarcelBeug9 years ago
Community Champion
Watch this video in which "Source" is the name of the previous step in my query.
Unfortunately, while typing, it jumped from the second line to the first line, but it is the same "Source".
- Anonymous8 years agoNot applicable
When I rename columns it breaks the tables I have made. It says all of the columns in the table are invalid and I have to redrag the newly named columns to get it to work again. Is there a way to get around this?