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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
gvg
Post Prodigy
Post Prodigy

How to reference table[column] as variables in a function

Hi folks,

I have a table with very many columns. I am looking to build a function (fChange) that can be called on any column. It looks like this:

 

= (myTable as table, myColumn as text) => let
    #"Replace Value" = Table.ReplaceValue( myTable, "some text", myTable[myColumn]{1} & " ccc",  // change to text on row 2 and " ccc"
    Replacer.ReplaceValue, {myColumn})
in
    #"Replace Value"

 

The function is supposed to be called using :

 

=fChange(TableFromPreviousStep, "Column78")

 

myTable[myColumn]{1} reference in line 2 is not working. Power Query interprets myColumn not as variable, but as the column name "myColumn". I need to have variable column name there so that I can call the function on any column. What is correct syntax to reference a column in a variable in "M" function? Failed to google find answer on the net.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@gvg , you may want to try

= (myTable as table, myColumn as text) =>
let
    #"Replace Value" = Table.ReplaceValue( myTable, "some text", Table.ToList(Table.SelectColumns(myTable, myColumn)){1} & " ccc", Replacer.ReplaceValue, {myColumn})
in
    #"Replace Value"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
gvg
Post Prodigy
Post Prodigy

Yep, that works. Thank you @CNENFRNL !

CNENFRNL
Community Champion
Community Champion

@gvg , you may want to try

= (myTable as table, myColumn as text) =>
let
    #"Replace Value" = Table.ReplaceValue( myTable, "some text", Table.ToList(Table.SelectColumns(myTable, myColumn)){1} & " ccc", Replacer.ReplaceValue, {myColumn})
in
    #"Replace Value"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.