+ Reply to Thread
Results 1 to 9 of 9

COUNTIF using OR Criteria with a cell reference to dates

  1. #1
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    COUNTIF using OR Criteria with a cell reference to dates

    I am trying to count the number of rows/records which had 'open' notes on a variable date, which involves checking for:
    • A Closed Date in the future
    • OR
    • No Closed Date at all (blank cell)

    There are other criterions which are straight forward and included in the COUNTIF, but I'm having trouble trying to get COUNTIF to recognise the Date in the future (Greater Than) because it uses a cell reference in the array, rather than a hard coded date manually typed into the formula.

    I'm trying to avoid using COUNTIFS()+COUNTIFS() because the formula will get quite large and I'm hoping there must be a way of using the array part that will pick up a cell reference?

    My current formula is:
    {=IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],{">&D27",""})),"")}

    The formula is correctly picking up the Received Date less than or equal to cell D27 (the variable date), and also the Closed Date which is blank (""), but it doesn't pick up the Closed Date greater than cell D27 (the variable date). I think this is because it is enclosed in speech marks so COUNTIF thinks it's looking for a text value of ">&D27".

    How can I get the array to recognise ">&D27" as "greater than cell D27" so that I can still use this handy OR element in the COUNTIF?

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF using OR Criteria with a cell reference to dates

    Hi Seaside- Unfortunately, Excel doesn't let you use cells in arrays. As you say, it's reading that reference as TEXT, so the test won't work. Try this:
    Please Login or Register  to view this content.
    BTW, I used SUMPRODUCT so you could enter this normally. No CSE required (I think...haven't tested it).

    Please click the Add Reputation star below any helpful posts, and use Thread Tools (up top) to mark your thread as SOLVED once you have your answer. Thanks!-Lee
    Last edited by leelnich; 08-17-2017 at 05:50 AM.

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: COUNTIF using OR Criteria with a cell reference to dates

    Perhaps this
    =IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],TEXT(D27,{""">""0",""}))),"")
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: COUNTIF using OR Criteria with a cell reference to dates

    SUMPRODUCT works perfectly, thank you very much.

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: COUNTIF using OR Criteria with a cell reference to dates

    You're most welcome! If complete, please mark your thread as SOLVED (Thread Tools up top). Thanks -Lee

    Please click the Add Reputation star below any helpful posts, and use Thread Tools (up top) to mark your thread as SOLVED once you have your answer. Thanks!-Lee

  6. #6
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: COUNTIF using OR Criteria with a cell reference to dates

    Quote Originally Posted by xlnitwit View Post
    Perhaps this
    =IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],TEXT(D27,{""">""0",""}))),"")
    This formula works too, until I input more "OR" elements, for example, I also want to include any rows/records which don't have a Complaint or the Complaint was raised after the date in D27;
    =IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],TEXT(D27,{""">""0",""}),Data[Complaint Date],TEXT(D27,{""">""0",""}))),"")

    The result brought back is not the same volume when I do a manual count/filter on the dataset. SUMPRODUCT does seem to be able to cater for the extra OR part:
    =IF(SourceSelected="A",SUMPRODUCT((Data[Notes on Case?]="Yes")*(Data[Received Date]<=D27)*((Data[Closed Date]>D27)+(Data[Closed Date]=""))*((Data[Complaint Date]>D27)+(Data[Complaint Date]=""))),"")

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: COUNTIF using OR Criteria with a cell reference to dates

    You need to alter the orientation of the second array if you use a second set of criteria
    =IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],TEXT(D27,{""">""0",""}),Data[Complaint Date],TEXT(D27,{""">""0";""}))),"")

  8. #8
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: COUNTIF using OR Criteria with a cell reference to dates

    Quote Originally Posted by xlnitwit View Post
    You need to alter the orientation of the second array if you use a second set of criteria
    =IF(SourceSelected="A",SUM(COUNTIFS(Data[Notes on Case?],"Yes",Data[Received Date],"<="&D27,Data[Closed Date],TEXT(D27,{""">""0",""}),Data[Complaint Date],TEXT(D27,{""">""0";""}))),"")
    Yes, that now works too. Brilliant.

    Thank you xlnitwit and leelnich for your speedy help on this. I have marked this as SOLVED.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: COUNTIF using OR Criteria with a cell reference to dates

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] using a cell reference for criteria in vba countif
    By crywolf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2017, 07:11 PM
  2. Return dates that match a single criteria (a countif criteria)
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2014, 12:43 PM
  3. COUNTIF, dates and blank cell criteria
    By luvthavodka in forum Excel General
    Replies: 6
    Last Post: 06-01-2006, 04:55 PM
  4. [SOLVED] Could the "Criteria" in COUNTIF function be a cell reference?
    By N Harkawat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  5. [SOLVED] Could the "Criteria" in COUNTIF function be a cell reference?
    By JohnSheenWSN in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  6. Could the "Criteria" in COUNTIF function be a cell reference?
    By JohnSheenWSN in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  7. [SOLVED] Could the "Criteria" in COUNTIF function be a cell reference?
    By JohnSheenWSN in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1