To count days between two dates (a range of dates), you need to use the COUNTIFS function instead of COUNTIF. To create a date range, you need to specify a lower date and an upper date. This tells Excel to count only days between the range of days.
Formula to Count Days Between Two Dates
You can use the following steps:
- First, enter the COUNTIFS function in a cell.
- After that, in the criteria_range1 argument, refer to the range where you have dates.
- Next, in the criterai1 argument, enter the greater than (>) and equal sign (=) and enclose between double quotation marks. And then, refer to the cell where you have the lower date.
- Now, in the criteria_range2, refer to the date range again.
- After that, in criteria2, enter the lower than (<) and equal sign (=) and enclose it between double quotation marks. And then, refer to the cell where you have the upper date.
- In the end, close the function and hit enter to get the result.
=COUNTIFS(A2:A17,">="&E2,A2:A17,"<="&F2)
How this Formula Works
To understand this formula, you can break it down into two parts.
- In the first part, you have the condition to test for the cells greater than and equal to the date you have in cell E2. i.e., 4-Nov-2022.
- In the second part, you have the condition to test for the cells which are lower than and equal to the date you have in cell F2. i.e., 4-Dec-2022.
So 15 cells have dates between the date range 4-Nov-2022 and 4-Dec-2022.
Note: Make sure to enter greater than (>), lower than (<), and equal (=) operators as text and surrounded by double quotation marks.
Use SUMPRODUCT to Count Between Dates
You can also use SUMPRODUCT to count dates between two dates, just like the following example:
=SUMPRODUCT(--(A2:A17<=F2),--(A2:A17>=E2))
Now let’s understand this formula step by step. But before that, you need to know that SUMPRODUCT can take an array in a single cell.
In the first part of the formula, you have a condition to check all the dates from the range. It will check which is lower and equal to the specified date. You can see it returns TRUE and FALSE.
After that, you have a double minus sign that converts these TRUE and FALSE into 1 and 0.
In the second part of the formula, you again have the condition to test. And it returns TRUE if that condition is met, else FALSE.
After that, the double minus sign converts TRUE and FALSE into 1 and 0.
At this point, you have two arrays. 1 means that the date in the range is between the specified date range.
SUMPRODUCT creates a product of these arrays and returns a single array, then sums values from that array which is the count of dates between the range.
ERROR RESULT #VALUE! AFTER THIS CONDITION
=COUNTIFS(Sheet1!N2:N1048576,”=”&D3,Sheet1!AR2:AR1024,”=”&”Vehicle Not Deliver Yet”)
The error in your formula occurs due to mismatched ranges. The ranges for the COUNTIFS function must be of the same size. In your case, the first range (Sheet1!N2:N1048576) is much larger than the second range (Sheet1!AR2:AR1024). Both ranges should have the same number of rows. To fix this, ensure that both ranges cover the same number of rows, like this:
=COUNTIFS(Sheet1!N2:N1024, "="&D3, Sheet1!AR2:AR1024, "="&"Vehicle Not Deliver Yet")
This should work without an error, as both ranges now have 1024 rows. If your dataset goes beyond row 1024, adjust the ranges accordingly.