Count a row if a specific date falls between two columns of dates

Tarver

Board Regular
Joined
Nov 15, 2012
Messages
109
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have two columns of dates, a start date and an end date. I need a formula to count the number of rows that have a start date before or during a specific month, and rows that have an end date during or after that month. I can't for the life of me figure out how to do this.

For example, let's count date ranges that fall in the month of January. There are six different possibilities, as I figure it, and I need to count four of them.

Start DateEnd Date
1/15/20191/20/2019 Both Dates within the month - COUNT
12/30/20182/15/2019Start date before, end date after - COUNT
12/28/20181/20/2019 End date within the month - COUNT
1/13/20182/15/2019 Start date within the month - COUNT
12/20/201812/31/2018 Both dates before the month - DON'T COUNT
2/20/20193/14/2019 Both dates after the month - DON'T COUNT

<tbody>
</tbody>

I've tried doing COUNTIFS combined with an AND and OR function, played with nesting IF with COUNTIF, etc., and I simply can't figure out how to do this. Any help is most appreciated.

BT
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this array formula.
In cell D2 January 1, in E2 January 31

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:71.29px;" /><col style="width:76.04px;" /><col style="width:38.97px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td style="background-color:#ffff00; font-weight:bold; text-align:center; ">Start Date</td><td style="background-color:#ffff00; font-weight:bold; text-align:center; ">End Date</td><td style="background-color:#ffff00; font-weight:bold; "> </td><td style="background-color:#ffff00; font-weight:bold; text-align:center; ">Start Date</td><td style="background-color:#ffff00; font-weight:bold; text-align:center; ">End Date</td><td style="background-color:#ffff00; font-weight:bold; text-align:center; ">Result</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td style="text-align:right; ">15/01/2019</td><td style="text-align:right; ">20/01/2019</td><td > </td><td style="text-align:right; ">01/01/2019</td><td style="text-align:right; ">31/01/2019</td><td style="text-align:right; ">4</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td style="text-align:right; ">30/12/2018</td><td style="text-align:right; ">15/02/2019</td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td style="text-align:right; ">28/12/2018</td><td style="text-align:right; ">20/01/2019</td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">13/01/2019</td><td style="text-align:right; ">15/02/2019</td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="text-align:right; ">20/12/2018</td><td style="text-align:right; ">31/12/2018</td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="text-align:right; ">20/02/2019</td><td style="text-align:right; ">14/03/2019</td><td > </td><td > </td><td > </td><td > </td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Array Formula</td></tr><tr><td >F2</td><td >{=SUM(IF(A2:A7 >= $D$2,IF(A2:A7 <= $E$2,1,0),IF(B2:B7 >= $D$2,IF(B2:B7 <= $E$2,1,IF($D$2 >= A2:A7,IF($D$2 <= B2:B7,1,0),0)),0)))}</td></tr></table></td></tr></table>


Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

----
(Maybe after this post come other simpler formulas :cool:)
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top