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 All,
I'm trying to create a function that reutrns a list based on the value of another column, but for the life of me can't figure out something seemingly basic. Hopefully you can help...
So I have a table that's basically this:
Id | Condition A? | Condition B?
1 | TRUE | FALSE
2 | TRUE | TRUE
3 | FALSE | TRUE
So my function should return the list of Id's where the condition is true, if I pass "Condition A" it should return {1, 2}. B should return {2, 3}. So this is what I have so far.
= let ListValuesByCondition= (DataTable as table, ReturnColumn as text) =>
Table.ToList(Table.SelectColumns((Table.SelectRows(DataTable, each ([#"Condition A?"] = true))), ReturnColumn))
in ListValuesByCondition
= FN_ListValuesByCondition(#"My Table", "Id")
But I want to pass the condition column ( ex: [#"Condition A?"] ) as a variable. And making it type list return nothing. Sounds like it's something obvious, but I haven't had much luck finding solutions. Thank you in advance!
Solved! Go to Solution.
Figured it out shortly after posting, but here's the solution in case anyone runs into the same.
So we're actually referencing a field instead of a column, and we can't use brackets since it will take the literal of the variable name. So instead we need to use Record.Field. It should look like:
= let ListValuesByCondition= (DataTable as table, ReturnColumn as text, ConditionColumn as text) =>
Table.ToList(Table.SelectColumns((Table.SelectRows(DataTable, each (Record.Field(_, ConditionColumn) = true)), ReturnColumn))
in ListValuesByCondition
= FN_ListValuesByCondition(#"My Table", "Id", "Condition A?")
Figured it out shortly after posting, but here's the solution in case anyone runs into the same.
So we're actually referencing a field instead of a column, and we can't use brackets since it will take the literal of the variable name. So instead we need to use Record.Field. It should look like:
= let ListValuesByCondition= (DataTable as table, ReturnColumn as text, ConditionColumn as text) =>
Table.ToList(Table.SelectColumns((Table.SelectRows(DataTable, each (Record.Field(_, ConditionColumn) = true)), ReturnColumn))
in ListValuesByCondition
= FN_ListValuesByCondition(#"My Table", "Id", "Condition A?")
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 |
|---|---|
| 55 | |
| 34 | |
| 31 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 71 | |
| 38 | |
| 35 | |
| 25 |