Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dynamically set the ColumnName in M query

Hello Everyone, 

 

I have a table where I have to use the table cell value in other table. Here Table Column Name is dynmically changing based on the user input. 

 

Below is the table: [TableName: Title]

Table.png

 

I have a code below working fine which is static.

= List.Accumulate
(
{0..Table.RowCount(Title)-1},
#"Changed Type1",
(old,current)=>
Table.AddColumn(old, Title[Title.Name]{current}, each Title[Value.Attributes.L01]{current}, type text) 
)

 

But I would like to pass L01 as dynamic. Based on the user input the value may change. Accordingly table name will also be changed. For example: When user input as L02, then table column name changed to Value.Attributes.L02. Here I have to concatenate in Title[Value.Attributes.L02]{current}

 

Is it possible to achieve? Thanks in advance

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

 

I could able to slove the problem by renaming the Column as "Axes" in table as Static in one step above. 

 

#"List Accumulate" = List.Accumulate
(
{0..Table.RowCount(#"TitleDim")-1},
#"Changed Type1",
(old,current)=>
Table.AddColumn(old, #"TitleDim"[Title.Name]{current}, each #"TitleDim"[Axes]{current}, type text)
),

 

 

 

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @Anonymous ,

 

This can probably be done using #section which creates a list of all queries (list, table, custom function, etc.) but what is your data source? 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Hello  @danextian  and  @v-alq-msft ,

 

Thanks for your reply. I have a Power Query (M formula) which has to support and work for other attributes too. 

 

My datasource is IBM TM1, using Tm1 Rest api I am pulling the data. 

 

I want to make my code more dynamic and convert to custom connector. I want to change the attribute in the M code based on the user input and tried the below, but its not working. Userinput could be L01, L02, L03 or some other values too.

 

ColName = "Value.Attributes."&L01&"", then I passed to

#"List Accumulate" = List.Accumulate
(
{0..Table.RowCount(#"TitleDim")-1},
#"Changed Type1",
(old,current)=>
Table.AddColumn(old, #"TitleDim"[Title.Name]{current}, each #"TitleDim"[ColName]{current}, type text)
),

 

how to achieve this? Is it Possible? 

 

 

Anonymous
Not applicable

Hi,

 

I could able to slove the problem by renaming the Column as "Axes" in table as Static in one step above. 

 

#"List Accumulate" = List.Accumulate
(
{0..Table.RowCount(#"TitleDim")-1},
#"Changed Type1",
(old,current)=>
Table.AddColumn(old, #"TitleDim"[Title.Name]{current}, each #"TitleDim"[Axes]{current}, type text)
),

 

 

 

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

I'd like to suggest you use 'Manage Parameter' to change column name dynamically. I created data to reproduce your scenario.

c1.png

 

You may go to 'Home' ribbon, click 'Manage Parameter' and set as below.

c2.png

 

Then you may go to 'Home' ribbon, click 'Advanced Editor', add a 'RenameColumn' step like follows. You need to use the parameter name to replace the value.

c4.png

 

Finally you may changed the value of 'ColumnName' parameter to control which column name it displays.

c5.png

c6.png

c7.png

c8.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.