You are here:

# Excel/Count if with multiple date parameters in multiple cells

Question
QUESTION: Hi Bob,

This a continuation of the same workbook that you helped me with conditional formatting.  Thanks, again for that help.  Now I'm stuck on a counting formula.  I'm going to need to do several variations of the same thing as listed below but believe if I can get one working example I can then modify it to make the others work.

Example report period dates = 10/1/13 – 12/31/13

If AX cell has a date, count it if 1) the AX cell date is equal to or in between the report period dates (10/1/13 – 12/31/13) and if 2) the AX cell date is 0-6 months greater than either the corresponding O (program start date) or P (program end date)cell dates.

Example 1 that would be counted
O2 = 6/1/13 (program start date)
P2 = 7/31/13 (program end date)
AX2 = 10/17/13 (new contact date)

Example 2 that would be counted
O2 = 8/1/13 (program start date)
P2 = blank-still in program (program end date)
AX2 = 10/17/13 (new contact date)

Example 3 that would NOT be counted
O2 = 2/1/13 (program start date)
P2 = 3/31/13 (program end date)
AX2 = 10/17/13 (new contact date)

Example 4 that would NOT be counted
O2 = 8/1/13 (program start date)
P2 = blank-still in program (program end date)
AX2 = 9/17/13 (new contact date)

I'm using excel 2010.  The actual formula/count result will be in the next worksheet.  The name of the data source worksheet is "Master data" (without quotes).  I know how to add the "Master data" reference to the various parts in the formula if you don't want to mess with it.

=AND('Master Data'!AX2>='Master Data'!\$N\$1,'Master Data'!AX2<='Master Data'!\$N\$2,OR('Master Data'!AX2<=DATE(YEAR('Master Data'!O2),MONTH('Master Data'!O2)+6,DAY('Master Data'!O2)),'Master Data'!AX2<=IF('Master Data'!P2=0,'Master Data'!T2,DATE(YEAR('Master Data'!P2),MONTH('Master Data'!P2)+6,DAY('Master Data'!P2)))))

This part:
DATE(YEAR(O2),MONTH(O2)+6,DAY(O2))
is 6 months after O2 and this part:
IF(P2=0,T2,DATE(YEAR(P2),MONTH(P2)+6,DAY(P2)))
is 6 months after P2, BUT if P2 is blank, it uses O2.

HTH

---------- FOLLOW-UP ----------

QUESTION: Hi Bob.

I tried it but am getting a "FALSE" result instead of "2", using my test data.  I'm wondering whether the "\$N\$1", "\$N\$2", and "T2" references are part of the problem?  I've attached a couple images in case they might help.

Dave

Sorry - the report dates were assumed to be in N1 and N2. Also, I forgot to take my intermediate reference to T2 out. This formula will produce True or False, not 1 or 2 -- "counting it" gives true, not counting it gives false.
Use this modified formula (no T2 reference), and put the report period dates in N1 & N2:

=AND(AX2>=\$N\$1,AX2<=\$N\$2,OR(AX2<=DATE(YEAR(O2),MONTH(O2)+6,DAY(O2)),AX2<=IF(P2=0,DATE(YEAR(O2),MONTH(O2)+6,DAY(O2)),DATE(YEAR(P2),MONTH(P2)+6,DAY(P2)))))
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Bob Umlas

##### Expertise

I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/

##### Experience

Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Publications
Excellence, The Expert, Microsoft

Education/Credentials
BA in math, Hofstra University, 1965

Awards and Honors
MVP
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks