How to fix "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

Alan Chen 60 Reputation points
2025-02-16T15:06:57.31+00:00

I write the following script but it doesnot work with error message, could anyone help to fix?

"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

User's image

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 49,715 Reputation points MVP Volunteer Moderator
    2025-02-16T15:49:09.07+00:00

    Your DAX formula is causing an error because CALCULATE(STARTOFYEAR('MTDYTD'[Date1]), YEAR('MTDYTD'[Date1])=YEAR(TODAY())) is attempting to apply a filter that returns multiple values rather than a single scalar value. The same issue exists for Monthstart.

    Try modifying your formula as follows:

    MTDYTD Selection =
    VAR TODAYDATE = TODAY()
    VAR Yearstart = CALCULATE( STARTOFYEAR( 'MTDYTD'[Date1] ), FILTER( 'MTDYTD', YEAR('MTDYTD'[Date1]) = YEAR(TODAYDATE) ) )
    VAR Monthstart = CALCULATE( STARTOFMONTH( 'MTDYTD'[Date1] ), FILTER( 'MTDYTD', YEAR('MTDYTD'[Date1]) = YEAR(TODAYDATE) && MONTH('MTDYTD'[Date1]) = MONTH(TODAYDATE) ) )
    
    VAR Result =
        UNION(
            ADDCOLUMNS( CALENDAR( Yearstart, TODAYDATE ), "Selection", "YTD" ),
            ADDCOLUMNS( CALENDAR( Monthstart, TODAYDATE ), "Selection", "MTD" )
        )
    RETURN
        Result
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.