+ Reply to Thread
Results 1 to 16 of 16

Can I nest Countifs Statements in an IF / OR statement?

  1. #1
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Can I nest Countifs Statements in an IF / OR statement?

    I am trying to count how many times certain letter combinations occur in a column based on the date and another geographical code. Here is what I came up with but the result is giving me FALSE as the return and it should be giving me 1 (not for true but for one occurrence).

    =IF(OR('2013 Data'!$G:$G=G13,'2013 Data'!$G:$G=G14,'2013 Data'!$G:$G=G15,'2013 Data'!$G:$G=G16,'2013 Data'!$G:$G=G17,'2013 Data'!$G:$G=G18),(COUNTIFS('2013 Data'!$I:$I,$A13,'2013 Data'!$D:$D,"ABC")+COUNTIFS('2013 Data'!$I:$I,$A13,'2013 Data'!$D:$D,"ACD")+COUNTIFS('2013 Data'!$I:$I,$A13,'2013 Data'!$D:$D,"ADF")+COUNTIFS('2013 Data'!$I:$I,$A13,'2013 Data'!$D:$D,"DFG")))

    The '2013 Data' sheet holds all of my Data, Column G on this sheet holds the geography code, Column I holds the date of occurrence, Column D holds the letter combinations

    There are six geographical codes I am asking for the data to occur in, those codes are in G13:G18
    The date I am asking it to look at is in A13

    I know that "DFG" occurs one time for the date I am asking for and in one of those six geographic areas but the formula is returning FALSE.

    Ideas?

    Thank you in advance for your help!!

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Can I nest Countifs Statements in an IF / OR statement?

    The first part of your formula is equating to FALSE

    Please Login or Register  to view this content.
    Change your formula to
    Please Login or Register  to view this content.
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Can I nest Countifs Statements in an IF / OR statement?

    If you space the formula out, you can see that you only have a TRUE result and no FALSE result. So, if none of the OR conditions is TRUE, you will get FALSE returned.

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Oh, and it's unlikely that you are going to get a whole column equal to one cell as in
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Regards, TMS
    Last edited by TMS; 10-02-2013 at 01:25 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,459

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Dear all,
    I afraid that OR(...) allways TRUE because G13,G14,...,G18 are always exist in G:G
    Sure that the formula can be shorten much, if the sample file is able to be posted.
    Quang PT

  5. #5
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    With the first suggested formula fix, it seems it is not eliminating data outside the geocode areas. I have posted a sample sheet. The first date on the Summary sheet should have 4 and not 6.

    Thank you again for your help.
    Attached Files Attached Files

  6. #6
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Shouldn't the answer be 3?

    Try
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Quote Originally Posted by TMShucks View Post

    Oh, and it's unlikely that you are going to get a whole column equal to one cell as in
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I can use COUNTIF('2013 Data'!G:G,G13) to count how many times the contents of G13 occurs in Column G of the data sheet. Using that same logic, can I not use IF('2013 Data'!G:G=G13, "FindMe") to create a TRUE condition when the contents of G13 are found?

  8. #8
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Quote Originally Posted by Ace_XL View Post
    Shouldn't the answer be 3?

    Try
    Please Login or Register  to view this content.
    UH... yes. 3 is correct - I hand counted wrong.

  9. #9
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Ace - since my actual data sheet is endless (over 5 thousand rows of data) and changes in actual length from week to week, limiting the formula to row numbers will not work. When I changed the formula to look at the whole column (i.e. '2013 Data'!$I:$I) Excel had a fit and told me it ran out of resources and couldn't calculate the formulas.

    Another idea?
    Last edited by CWatsonJr; 10-02-2013 at 03:09 PM. Reason: typo

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Put 1,2,3,4,5 in G13, G14, G15, G16 and G17 respectively and put 1,2,3,4,5 on Sheet '2013 Data'!$G:$G, anywhere you like. Put the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    anywhere you like on the original sheet (where you populated G13:G14). You get "no".

    You are trying to compare an entire column to a single cell. That's not the same as a COUNTIF. If you said:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    you will get "yes".

    I can't explain it a different way.

    Regards, TMS

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Can I nest Countifs Statements in an IF / OR statement?

    You can define Dynamic Named Ranges for the columns you are interested in:

    nrType:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    nrGEO:
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Then refer to the named ranges rather than fixed cell references.


    Regards, TMS

  12. #12
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Another alternative if you want to keep referring to entire columns

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Quote Originally Posted by Ace_XL View Post
    Another alternative if you want to keep referring to entire columns

    Please Login or Register  to view this content.
    Perfect!!!!!!! Thank you very much.

    You guys here are so awesome!!!!!!!!!

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Can I nest Countifs Statements in an IF / OR statement?

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  15. #15
    Forum Contributor
    Join Date
    02-27-2004
    Location
    California, United States
    MS-Off Ver
    Excel 2016
    Posts
    315

    Re: Can I nest Countifs Statements in an IF / OR statement?

    Thanks TMShucks - I was hunting around on the page trying to remember how to mark it as solved.

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Can I nest Countifs Statements in an IF / OR statement?

    You're welcome. Thanks for the rep.

+ 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. Countifs with nest left
    By namluke in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-22-2013, 06:33 AM
  2. [SOLVED] Can I nest IF statements, if the first one is checking for data?
    By Barnaclebot in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-15-2013, 03:25 PM
  3. [SOLVED] How to nest two IF statements
    By wolfgang713 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 01-15-2013, 09:50 AM
  4. Nest Lookup With If And Statements
    By opeyemi1 in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 02-19-2008, 11:57 AM
  5. [SOLVED] How do I nest IF statements to only return value if both true?
    By kvnexcel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-14-2006, 01:40 PM

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