+ Reply to Thread
Results 1 to 12 of 12

Countif with multiple AND/OR criteria

  1. #1
    Registered User
    Join Date
    11-18-2011
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2016
    Posts
    31

    Countif with multiple AND/OR criteria

    I'm trying to count how many accounts of a given type appear for a given sales rep. If you see my attachment, B4 needs to show the total number of only the Medcare Company, Inv Lab and Physicians accounts with Extended hours are listed for Andrew Williams on Sheet 2 "Accounts". The formula below doesn't work and I'm not sure why:
    =COUNTIF(Accounts!$B:$B,A4)*AND(OR(Accounts!$F:$F="Medcare Company",Accounts!$F:$F="Inv Lab",Accounts!$F:$F="Physicians",Accounts!$H:$H="Yes"))

    REP ID countif test.xlsx
    Last edited by kazphilips; 05-17-2012 at 12:34 PM.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Countif with multiple AND/OR criteria

    In B4

    =SUM(COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Medcare Company",Accounts!I:I,"Yes"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Inv Lab",Accounts!I:I,"Yes"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Physicians",Accounts!I:I,"Yes"))

    You indicate the correct answer should be 34 but I only see 5 by looking at it and the above formula confirms 5.

  3. #3
    Registered User
    Join Date
    11-18-2011
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: Countif with multiple AND/OR criteria

    I'm sorry, quick correction to the requirement here... I need a count of these account types PLUS all accounts with extended hours (regardless of account type).

    Thanks!

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Countif with multiple AND/OR criteria

    I don't follow what exactly you need but you should be able to adapt the formula I gave you.

  5. #5
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Re: Countif with multiple AND/OR criteria

    I think this works:
    =SUM(COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Medcare Company",Accounts!I:I,"Yes"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Inv Lab",Accounts!$I:$I,"Yes"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Physicians",Accounts!I:I,"Yes"))+COUNTIF(Accounts!I:I,"Yes")

    I get 33 but I counted up the extended hours and it looks like just 28 of them plus the 5 specific carriers wihch gives me only 33.

    I tried, Hope this helps.

  6. #6
    Registered User
    Join Date
    11-18-2011
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: Countif with multiple AND/OR criteria

    Thanks for your help. I entered the following formula which works...sorta. The problem is, the count isn't accurate because a physician with extended hours ends up being counted twice, once for being a physician and once for having extended hours. Andrew ends up with 39 instead of 34. I'm still working on it.

    =SUM(COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Medcare Company"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Inv Lab"),COUNTIFS(Accounts!B:B,A4,Accounts!F:F,"Physicians"),COUNTIFS(Accounts!B:B,A4,Accounts!I:I,"Yes"))

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: Countif with multiple AND/OR criteria

    Try this version to avoid double-counting

    =SUM(COUNTIFS(Accounts!B:B,A4,Accounts!F:F,{"Medcare Company","Inv Lab","Physicians"},Accounts!I:I,"<>Yes"),COUNTIFS(Accounts!B:B,A4,Accounts!I:I,"Yes"))

    I believe it gives the results you suggest, i.e. 34, 28 and 42
    Audere est facere

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Countif with multiple AND/OR criteria

    the count isn't accurate because a physician with extended hours ends up being counted twice, once for being a physician and once for having extended hours
    That's why I said I didn't follow exactly what you want. I assumed you didn't want a double count but I don't get what it is that you do want.
    Andrew appears 44 times. He is associated with the 3 specified accounts 34 times. Only 5 of those associations have a Yes in Extended Hours.
    So what is it that you are looking for?

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Countif with multiple AND/OR criteria

    @daddylonglegs
    Your formula is equivalent to:
    =SUM(COUNTIFS(Accounts!B:B,A4,Accounts!F:F,{"Medcare Company","Inv Lab","Physicians"}))
    isn't it? I believe it just disregards the Extended Hours criteria.

    EDIT: Ah, I see it now. Never mind.
    Last edited by Cutter; 05-16-2012 at 05:45 PM.

  10. #10
    Registered User
    Join Date
    11-18-2011
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: Countif with multiple AND/OR criteria

    Cutter, pretty much any of these formulas would work, except I also need the OR statement to include the Extended Hours. The original spreadsheet has 100K+ records and many of them have extended hours (I:I="Yes") but do not fall into the three given categories in F:F, hence the OR statement.

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: Countif with multiple AND/OR criteria

    Did you try my suggestion - it gives the results you wanted.......

  12. #12
    Registered User
    Join Date
    11-18-2011
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: Countif with multiple AND/OR criteria

    @daddylonglegs... Perfect, THANKS!!!

+ 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