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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
geraldmeunier
New Member

dynamic column name in formula

Hi everyone,

 

Let's say I have several columns A, B and C

I create a new column with a formula like :

= [A] + [B]

 

Let's say I want column B to be driven from a function that we could call fnGetParamater("Parameter_a")

 

Is there a way to have a syntax that would be like :

= [A] + ["& fnGetParamater("Parameter_a")& "]

 

I know this is not working but you get the idea...

Any suggestion welcome !

 

Gerald

 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Not completely sure what you're after, but could it be this?:

 

[A] + Record.Field(_, fnGetParamater("Parameter_a") )

 

It will return the value from the  colum whose name the function returns.

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
ImkeF
Community Champion
Community Champion

Not completely sure what you're after, but could it be this?:

 

[A] + Record.Field(_, fnGetParamater("Parameter_a") )

 

It will return the value from the  colum whose name the function returns.

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks a lot !
for my own culture (yes I'm new to power query), what does the underscore really stand for in the

"Record.Field(_, ColumnName)" formula ?

Hi @geraldmeunier 

it stands for the record of the current row (if you use your fomula in a Table.AddColums-formula for exapmle).

There, the third argument is a function into which the current record will be automatically pumped into. 

There's some syntax sugar involved: https://docs.microsoft.com/en-us/powerquery-m/understanding-power-query-m-functions 

which means that you can use reference the columns with square brackets only, but if you cannot use that shortcut syntax, you have to explictly reference the record. When the "each"-keyword is used, this can be done by using the underscore "_",

but if you want to nest functions, you can replace the each by ordinary functions like so:

 

(x) => MyFunction(x)

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors