Forum Discussion

tomperro's avatar
tomperro
Helper V
9 months ago
Solved

UDF Question

I created a User Defines Function and it seems to be working but when I use it in a measure, it is retunring an incorrect value.    Here is my function:     function fnFYTDAverage =         ...
  • DaleT's avatar
    DaleT
    9 months ago

    It seems you missed a definition of the parameter. Refer to the function code below, please. The function can accept a measure in this way ": anyref expr" rather than considering it as a scalar. Please also refer to doc here https://learn.microsoft.com/en-us/dax/best-practices/dax-user-defined-functions#type 

    DEFINE
    	FUNCTION fnFYTDAverage_new = (_measure: anyref expr) =>
    		AVERAGEX(
    			DATESYTD(DateTable[Datekey]),
    			_measure
    		)