Forum Discussion
UDF question
Hi,
Can anyone help me figure out what’s causing the error when I convert this measure into a UDF?
Error:
DEP_P = ppct('2. FU_KIDS','2. FU_KIDS'[volume],'2. FU_KIDS'[N_FU_DEP_NMISS_C_3])
The COUNTA function only accepts a column reference as an argument.
Measure:
DEP_P = DIVIDE(COUNTA('2. FU_KIDS'[VOLUME]), CALCULATE(COUNTA('2. FU_KIDS'[VOLUME]), ALLSELECTED('2. FU_KIDS'), VALUES('2. FU_KIDS'[N_FU_DEP_NMISS_C_3]) ))
UDF:
DEFINE
FUNCTION ppct=(vtable,volumeColumn, groupColumn) =>
DIVIDE ( COUNTA ( volumeColumn ), CALCULATE ( COUNTA ( volumeColumn ), ALLSELECTED ( vtable ), VALUES ( groupColumn ) ) )
Hi Vioneli ,
You need to define what type of input you have for each value try the following:
FUNCTION ppct=(vtable: anyref , volumeColumn: anyref, groupColumn: anyref) => DIVIDE ( COUNTA ( volumeColumn ), CALCULATE ( COUNTA ( volumeColumn ), ALLSELECTED ( vtable ), VALUES ( groupColumn ) ) )Check the types in the documentation:
https://learn.microsoft.com/en-us/dax/best-practices/dax-user-defined-functions#type
1 Reply
- MFelixSuper User
Hi Vioneli ,
You need to define what type of input you have for each value try the following:
FUNCTION ppct=(vtable: anyref , volumeColumn: anyref, groupColumn: anyref) => DIVIDE ( COUNTA ( volumeColumn ), CALCULATE ( COUNTA ( volumeColumn ), ALLSELECTED ( vtable ), VALUES ( groupColumn ) ) )Check the types in the documentation:
https://learn.microsoft.com/en-us/dax/best-practices/dax-user-defined-functions#type