Forum Discussion
olimilo
Post Prodigy
5 years agoCan I parameterize the Table.ReplaceValue command in a custom function?
I made the custom function below as I need to run the same function for 15+ columns, basically to replace colA with colB if it isn't null, otherwise to retain the value of colA: let updateFie...
LillyBeast
3 years agoFrequent Visitor
It needs an Evaluate.Expression wrap to allow running text as M-Code. See this example
Also, Table.ReplaceValue is simply passing three arguments - (in_value, look_for, replace_with) - to any function. Replacer.ReplaceValue is just a function that is used in the documentation, without really explaining how that works.
So, try this:
Evaluate.Expression(
"Table.ReplaceValue(
table
, each _" & ColA & "
, each _" & ColB & "
, (value, value_in_ColA, value_in_ColB) => value_in_ColA ?? value_in_ColB
, {" & ColA & "}
)"
,[Table.ReplaceValue = Table.ReplaceValue]
)
* - `??` operator is M-Code's null-coalesce