Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
KaterinaB
Helper II
Helper II

Converting existing simple measure to UDF - cannot determine a single value for column

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:

DEFINE
    FUNCTION LastMonthCalc = (ResultExpression : SCALAR EXPR, DateColumn: SCALAR DATETIME VAL) =>
        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])}


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


1 ACCEPTED SOLUTION
johnt75
Super User
Super User

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]
    )
}

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

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

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.