Site icon ExcelNotes

How to Count Cases based on Start and End Dates

In many situations, we need to count the cases that fall in a year based on the start and end dates. For example, there are many contracts in a company that start and end on different dates.

You could only have the following possibilities for all the contracts in 2015 when considering the start and end dates.

To be able to count all the contracts that ever exist in a year from Jan 1, 2015 to Dec 31, 2015 based on the start and end dates, we need to get the 4 possibilities with green lines.

Please use the following formula and change the start and end dates to your own.

=IF(OR(AND(A2>=DATEVALUE("2015/01/01"), A2<=DATEVALUE("2015/12/31")), AND(B2>=DATEVALUE("2015/01/01"), B2<=DATEVALUE("2015/12/31")), AND(A2<=DATEVALUE("2015/01/01"), B2>=DATEVALUE("2015/12/31"))), "2015", "")

Where A2 is the Start date and B2 is the End Date;

This formula works but it is too long. If you watch the drawing above carefully, you will find all the contracts in a year (or any period) have their start dates on or before December 31, 2015, and all the end dates are on or after January 1, 2015. The following formula will also do the work but it is way short.

=IF(AND(A2<=DATEVALUE("2015/12/31"),B2>=DATEVALUE("2015/01/01")),"2015","")

Where A2 is the cell with the start date and B2 is the cell with the end date.

After you label each contract, you can easily count the total by using the COUNTIF function. In the example above, the count of contracts in 2015:

=COUNTIF(D2:D7,"2015")

The result will return to 4.

Exit mobile version