Search code examples
datetimegoogle-sheetscomparison-operatorsgoogle-sheets-formula

Countifs/Sumifs with Dates and multiple statements not working


PROBLEM: I'm trying to do a countifs (same problem with a sumifs statement) statement where I give out the count of all cells which have a date in between two given dates.

Sheet 2 holds the cells with the date and in Sheet one I have Dates like this: A7 e.g. holds 12/1/2018 and B7 hold 12/31/2018.

ATTEMPT:

SUMIFS('Sheet2'!$K$1:$K, 'Sheet2'!$A$1:$A, ">="&$A7, 'Sheet2'!$A$1:$A, "<="&$B7)

OR with the Countifs statement just

COUNTIFS('Sheet2'!$A$1:$A, ">="&$A7, 'Sheet2'!$A$1:$A, "<="&$B7)

OR with FILTER

SUM(FILTER('Sheet2'!$K$1:$K; 'Sheet2'!$A$1:$A>=$A7; 'Sheet2'!$A$1:$A<=$A7))

ASSUMPTION: I think what happens is that the "=" operator gets ignored. So e.g. all dates that are exact 12/31/2018 or 12/1/2018 get ignored. I haven't found a workaround so far.

Here is an example sheet: https://docs.google.com/spreadsheets/d/1E1-oBlsAJqp9viTsskzXgbvzgGB93cY1_byK7Hano0Q/edit?usp=sharing


Solution

  • SOLUTION: You need to format the calls as a number. Doing so with the google sheets menu does not make any difference at all.

    Here is the formula I used for making it work:

    =ArrayFormula(REGEXREPLACE((K1:K); "[^\d\.]+";)*1)