Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi guys, I need your knowledge 😄
I am trying to pass the name of a column as a variable to create a table from a custom function.
this M code work:
(tabla as table, fecha as date, name as text) =>
let
nameColumn = "Full Name",
Origen = tabla,
#"Filtro" = Table.SelectRows(Origen, each ( [Full Name] = name) and ( [Created Date] = fecha))
in
#"Filtro"
but I would like something like this:
(tabla as table, fecha as date, name as text,nameColumn) =>
let
Origen = tabla,
#"Filtro" = Table.SelectRows(Origen, each ( [nameColumn] = name) and ( [Created Date] = fecha))
in
#"Filtro"
but I get the following error; "Expression.Error: The field 'nameColumn' of the record wasn't found"
Please any idea why the variable is not recognised in the filter context?
Solved! Go to Solution.
Hi, I found the solution in this post.
My code is as follows:
(tabla as table,nameColumn as text, fecha as date, name as text) =>
let
Origen = tabla,
#"Filtro" = Table.SelectRows(Origen, each ( Record.Field(_,nameColumn) = name) and ( [Created Date] = fecha))
in
#"Filtro"
the solution is the function:
Record.Field(record as record, field as text) as any
Hi, I found the solution in this post.
My code is as follows:
(tabla as table,nameColumn as text, fecha as date, name as text) =>
let
Origen = tabla,
#"Filtro" = Table.SelectRows(Origen, each ( Record.Field(_,nameColumn) = name) and ( [Created Date] = fecha))
in
#"Filtro"
the solution is the function:
Record.Field(record as record, field as text) as any
Yep. And the function Table.Column is table equivalent of Record.Field (it returns a list rather than a single value).
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |