Forum Discussion
Dynamic column name from its value
Hi
Is there any way to dynamically change column name from its values. I think it might be possible using advanced editor, but i'm not very good at writing M.
I have Dimension table and i want Dimension_name column to have its name dynamically from its values whitch is same in every row in this case.
I need this that i can use same template in every customer case and i dont have to change Dimension names every time i change data source.
There might be easier solutions and i welcome every solution you can give me.
thanks
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".
14 Replies
- MarcelBeugCommunity Champion
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.
- pagerFrequent 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!
- MarcelBeugCommunity 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".