Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
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.
Solved! Go to Solution.
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
)
Hi @tomperro ,
Your _Measure argument (PercentDiscussedFYTD_AVG) returns text, not a number because you wrapped it with the FORMAT() function.
In DAX, FORMAT() converts a numeric value into a string (text). When you then try to use that text value inside an iterator like AVERAGEX, DAX treats it as blank or fails implicit conversion leading to incorrect results.
Create a numeric measure (no FORMAT)
PercentDiscussedFYTD_AVG =
AVERAGEX(
DATESYTD('Calendar'[Date], "9/30"),
[~PercentDiscussedWithEmployee]
)
Use that in your function-based measure
DiscussedFYTD = fnFYTDAverage([PercentDiscussedFYTD_AVG])
If you want to show it as a percentage with 2 decimals, format the final measure in the model or in the visual.
DiscussedFYTD =
VAR _Result = fnFYTDAverage([PercentDiscussedFYTD_AVG])
RETURN
FORMAT(_Result, "0.00%")
set the measure’s format string to “0.00%” in the model instead of using FORMAT() in DAX.
If my response as resolved your issue, please accept my response as solution and please give kudos
Thanks,
Dinesh
Hi
Based on a quick look, the DiscussedFYTD should be fnFYTDAverage([~PercentDiscussedWithEmployee]), is this the cause?
Yes, that ls what I have in the pbix, I updated my original post
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
)
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 63 | |
| 51 | |
| 41 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 125 | |
| 108 | |
| 46 | |
| 29 | |
| 27 |