Search code examples
powerbidaxdaxstudio

A table of multiple values was supplied where a single value was expected. Error message when trying to count rows


I've got the following DAX measure

count_failures = 
COUNTROWS(FILTER('Complaint', DATESBETWEEN('Date'[Date], [End Month 4], [Start Month 2])))

I'm trying to count the rows on the 'Complaint' table, for all cases where the date is between End Month 4 and Start Month 2

End Month 4 = EOMONTH([End Month 1], -3) + time(23,59,59)

Start Month 2 = EOMONTH(TODAY(), -2) + 1

The 'Complaint' table is connected to the Date table on the data model.

I keep getting an error message when I try to display this value on a table that says "MdxScript(Model) (876, 31) Calculation error in measure '_Measures'[count_failures]: A table of multiple values was supplied where a single value was expected.

What am I doing wrong? I am just counting rows based in a condition, why am I getting an error message about multiple values?


Solution

  • FILTER function expects condition as a Boolean expression (true or false), while DATESBETWEEN returns a table (list of all dates between start and end date). Hence the error - instead of one true/false you are trying to use multiple values.

    To fix, replace FILTER with CALCULATETABLE:

    count_failures =
    COUNTROWS (
        CALCULATETABLE (
            'Complaint',
            DATESBETWEEN ( 'Date'[Date], [End Month 4], [Start Month 2] )
        )
    )