Forum Discussion
DAX UDF – Can a Function Accept Multiple Column References?
I defined a simple function like this, which works perfectly when passing a single column reference:
DEFINE FUNCTION get_table = (col:anyref) =>
ALLSELECTED(col)
get_table(DimProduct[Category])
However, I would like to reuse the same function and pass multiple columns, like this:
get_table(DimProduct[Category], DimProduct[Subcategory])
Currently, this does not work.
From what I understand:
UDFs do not support variadic parameters
There is no array/list-of-columns type in DAX
Overloading is not supported
At the moment, the only workaround seems to be defining separate functions for each number of column parameters (e.g., 2-column version, 3-column version, etc.).
Is there currently any supported way for a DAX UDF to accept multiple column references dynamically?
If not, is this a known limitation and potentially on the roadmap?
Thank you.
This is a known limitation. There is ongoing discussion about potential solutions, but nothing has been finalized yet. If the input columns are known in advance, you can pass their names into the function as a small table and then use the SWITCH function to map the strings back to column references.
1 Reply
- jeffrey_wang
Power BI Team
This is a known limitation. There is ongoing discussion about potential solutions, but nothing has been finalized yet. If the input columns are known in advance, you can pass their names into the function as a small table and then use the SWITCH function to map the strings back to column references.