This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreGet Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.
Hi, newbie to UDFs here, so apologize upfront for the simplicity of the question.
I am trying to test how to implement this converting some simple existing measure patterns into UDFs.
We have a test dataset with some "Last Month" and "Second to Last Month" measures, with such structure
LastMonthProfiles =
VAR LastMonthStart = DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1)
RETURN
CALCULATE(
SUM('Interest Profiles'[Total number of profiles]),
'Interest Profiles'[Month] = LastMonthStart
)
SecondToLastMonthProfiles =
VAR SecondtoLastMonthStart = DATE(YEAR(TODAY()), MONTH(TODAY()) - 2, 1)
RETURN
CALCULATE(
SUM('Interest Profiles'[Total number of profiles]),
'Interest Profiles'[Month] = SecondtoLastMonthStart
)
LastMonthLeads =
VAR LastMonthStart = DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1)
RETURN
CALCULATE(
SUM(MQLs[Number of Leads]),
MQLs[Month] = LastMonthStart
)
SecondtoLastMonthLeads =
VAR SecondtoLastMonthStart = DATE(YEAR(TODAY()), MONTH(TODAY()) - 2, 1)
RETURN
CALCULATE(
SUM(MQLs[Number of Leads]),
MQLs[Month] = SecondtoLastMonthStart
)
I want to have UDF defining the expression, the date column and how many months into the past it should look. I first started just to simply have UDF for Last Month:
I am getting an error: A single value for column 'Month' in table 'Interest Profiles' cannot be determined. This can happen when a measure or function formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result
I dont get that error in my existing measures
Solved! Go to Solution.
The problem is the type declaration of DateColumn. The function is expecting a scalar value, but you actually want to pass in a column, as you will be applying a filter on that column. Try
DEFINE
FUNCTION LastMonthCalc = (
ResultExpression : SCALAR EXPR,
DateColumn : COLUMNREF
) =>
VAR LastMonth =
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
RETURN
CALCULATE ( ResultExpression, DateColumn = LastMonth )
EVALUATE
{
LastMonthCalc (
SUM ( 'Interest Profiles'[Total number of profiles] ),
'Interest Profiles'[Month]
)
}
The problem is the type declaration of DateColumn. The function is expecting a scalar value, but you actually want to pass in a column, as you will be applying a filter on that column. Try
DEFINE
FUNCTION LastMonthCalc = (
ResultExpression : SCALAR EXPR,
DateColumn : COLUMNREF
) =>
VAR LastMonth =
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
RETURN
CALCULATE ( ResultExpression, DateColumn = LastMonth )
EVALUATE
{
LastMonthCalc (
SUM ( 'Interest Profiles'[Total number of profiles] ),
'Interest Profiles'[Month]
)
}
Yep, that was the issue, thanks for the quick help
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.