+ Reply to Thread
Results 1 to 13 of 13

countif with multiple conditions

  1. #1
    Registered User
    Join Date
    06-16-2010
    Location
    Minnetonka, MN
    MS-Off Ver
    Excel 2010
    Posts
    43

    Exclamation countif with multiple conditions

    Hello everyone,

    I am wondering if it is possible to use the countif function or any other ones to take into account multiple conditions? Here is my example and what I am trying to calculate:

    I have 1000 records and column A = Industry, column B = product.

    I am trying to count the number of records that fall within the following 3 industries and 3 products:

    Industry: Sporting Goods, Law Firm, Fitness Club
    Product: Phone, Cable, Internet

    Any combination of the 3 is what I'm trying to count (ex. SG and Phone, LF and Internet, FC and Phone, SG and Internet, etc.).

    If I use the countif function i will have to do 9 statements to cover every example and I don't want to do that. Is there a better formula/function/way to get this? Please help!!!
    Last edited by vancoservices; 06-18-2010 at 09:35 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: countif with multiple conditions

    have you tried countifs ?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    Given the OR nature of the condition, perhaps:

    =SUMPRODUCT(--ISNUMBER(SEARCH({"Sporting Goods","Law Firm","Fitness Club"},A1:A1000)),--ISNUMBER(SEARCH({"Cable","Phone","Internet"},B1:B1000)))

  4. #4
    Registered User
    Join Date
    06-02-2010
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: countif with multiple conditions

    If you are using excel 2007 you can use countifs

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    Quote Originally Posted by vancoservices
    Any combination of the 3 is what I'm trying to count (ex. SG and Phone, LF and Internet, FC and Phone, SG and Internet, etc.).

    If I use the countif function i will have to do 9 statements to cover every example and I don't want to do that.
    Quote Originally Posted by scottwhittaker2333
    If you are using excel 2007 you can use countifs
    @sscottwhittaker2333: you would still need 9 separate COUNTIFS given the AND nature of the function.

    Given the OP initial post I would say that actually precludes COUNTIFS as a viable option.

  6. #6
    Registered User
    Join Date
    06-16-2010
    Location
    Minnetonka, MN
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: countif with multiple conditions

    DonkeyOte is right, countifs does not work, I tried that a long time ago. It would work if I only wanted 1 variable in each column but I have 3 so it returns an incorrect number.

    I tried =SUMPRODUCT(--ISNUMBER(SEARCH({"Sporting Goods","Law Firm","Fitness Club"},A1:A1000)),--ISNUMBER(SEARCH({"Cable","Phone","Internet"},B1:B1000))) but it gave me an incorrect value as well. It was close but it looked like it wasn't including one of the variables.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    Quote Originally Posted by vancoservices
    I tried...[SUMPRODUCT formula]...but it gave me an incorrect value as well
    Please post a sample file illustrating as such.

    edit: hang on - yes you're right that won't work...

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    This extended version should work

    Please Login or Register  to view this content.
    in the above H1:I3 contain column A & B criterion

    I confess I am suffering something of a brain freeze at present re: shortened version

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: countif with multiple conditions

    what's wrong with sum 9 countifs? once its done its done

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    If you don't need to conduct a SEARCH (ie no partial matching required) such that a MATCH can be used then:

    =SUMPRODUCT(ISNUMBER(MATCH(A1:A1000,H1:H3,0))*ISNUMBER(MATCH(B1:B1000,I1:I3,0)))

    should work (where H1:I3 contain criterion)

    Not sure why I went down the SEARCH route in truth - nothing in the thread thus far implies it's required.

  11. #11
    Registered User
    Join Date
    06-16-2010
    Location
    Minnetonka, MN
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: countif with multiple conditions

    The sumproduct(sign(isnumber(search worked! There isn't any partial matching so I will for sure try the formula with match.

    Now to add more confusion...... If in the same example there is a column C called Upgrade Y/N and I wanted to add that into the equation, how should I add that? (searching for the same thing I did before but only counting records with a "Y")

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif with multiple conditions

    Using the MATCH example for sake of simplicity...

    =SUMPRODUCT((C1:C1000="Y")*ISNUMBER(MATCH(A1:A1000,H1:H3,0))*ISNUMBER(MATCH(B1:B1000,I1:I3,0)))

  13. #13
    Registered User
    Join Date
    06-16-2010
    Location
    Minnetonka, MN
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: countif with multiple conditions

    DonkeyOte you're awesome! Problem completely solved!!!! Thanks for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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