Question

Let's say that in column A, I have a list of starting dates and in column B, I have a list of ending dates. I wish to build one formula (without adding an extra column) that counts how many time the ending date exceeds 120 days from the starting date.

I tried the following formula in C1:

=COUNTIF(B:B,A:A-120)

but it's not working since the second attribute of the COUNTIF formula is a criteria, it doesn't seem to accept a range. It treats A:A as A1 because I put my formula in C1.

Note: it needs to be solved with only one formula, can't add extra columns or arrays, and no VBA.

UPDATE: some of rows have "NULL" written when no dates are available and therefore it doesn't work with =SUMPRODUCT(--(A:A<B:B-120))

Was it helpful?

Solution

You could use SUMPRODUCT instead, where you can use ranges:

=SUMPRODUCT(--(A:A<B:B-120))

If A:A is smaller than B:B after removing 120 days, then (A:A<B:B-120) will return true for each row where this applies, and false otherwise.

-- at the start will convert those to 1s and 0s respectively and SUMPRODUCT add them.

Note that the formula will be faster if you use a smaller range, e.g. A1:A100 and B1:B100 (or whatever range you're counting).


Try using this if you have non-dates in your range as well:

=SUM(IFERROR(A:A<B:B-120,0)*1)

And press Ctrl+Shift+Enter after typing in the formula to array invoke it (you can use SUMPRODUCT, but it will require the array invocation so you might as well just use SUM) .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top