+ Reply to Thread
Results 1 to 8 of 8

Multiple criteria in countif

  1. #1
    Registered User
    Join Date
    07-20-2012
    Location
    Buffalo
    MS-Off Ver
    Excel 2007
    Posts
    16

    Multiple criteria in countif

    I have a countif statement that works fine but I want to add another criteria set.

    Current formula:

    =COUNTIF(S21:U300,"[A] Cancelled Enroute") + COUNTIF(S21:U300,"[B] Cancelled Enroute")

    I now need it to count as above only if the first character in O21:O300 is "2"

    I've tried a couple sumproduct ideas and a dcount that was suggested but can't get anywhere with them.

    Any help would be great.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Multiple criteria in countif

    Try this formula

    =SUMPRODUCT((LEFT(O21:O300)="2")*ISNUMBER(MATCH(S21:U300,{"[A] Cancelled Enroute","[B] Cancelled Enroute"},0)))
    Audere est facere

  3. #3
    Registered User
    Join Date
    07-20-2012
    Location
    Buffalo
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Multiple criteria in countif

    Worked perfect. Would you mind explaining it to me?

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Multiple criteria in countif

    Perhaps
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Multiple criteria in countif

    Quote Originally Posted by Pepe Le Mokko View Post
    Perhaps
    Please Login or Register  to view this content.
    Pepe,

    I think it is a time for a coffee

    Each additional range must have the same number of rows and columns as the criteria_range1

    It must be Range, not arrays
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Multiple criteria in countif

    Quote Originally Posted by Abarency View Post
    Would you mind explaining it to me?
    Using ISNUMBER and MATCH is a standard way to check a range against multiple values, so when you use

    MATCH(S21:U300,{"[A] Cancelled Enroute","[B] Cancelled Enroute"},0)

    That returns an "array" of values the same size as S21:U300, if the cell matches one or other of those text values then you get a number, otherwise #N/A, so when that's wrapped in ISNUMBER this part

    ISNUMBER(MATCH(S21:U300,{"[A] Cancelled Enroute","[B] Cancelled Enroute"},0))

    returns an array of TRUE/FALSE values depending on whether the cells match, then when you multiply by this:

    (LEFT(O21:O300)="2")

    which also returns a column of TRUE/FALSE values, you only get 1 when both are true, so you only need to sum the resultant array, every 1 represents a matched text value in a row where col O value begins with 2. SUM could be used rather than SUMPRODUCT but the latter doesn't require CTRL+SHIFT+ENTER

  7. #7
    Registered User
    Join Date
    07-20-2012
    Location
    Buffalo
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Multiple criteria in countif

    Not to be a pain but look at this...

    =SUMPRODUCT((LEFT(CAO!O21:O300)>"1")*ISNUMBER(MATCH(CAO!S21:U300,{"1*","2*"},1)))

    Returns 125. Should be 126. There are 125 records with "2" and one "1"

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Multiple criteria in countif

    Wildcards don't work in that part of the MATCH function - I'd use LEFT again, i.e.

    =SUMPRODUCT((LEFT(CAO!O21:O300)>"1")*ISNUMBER(MATCH(LEFT(CAO!S21:U300),{"1","2"},0)))

+ 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