+ Reply to Thread
Results 1 to 12 of 12

COUNTIFS and multiple criteria per cell

  1. #1
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    COUNTIFS and multiple criteria per cell

    Hello All,

    I'm trying to construct a formula to accurately capture the following data:

    ABCD / DEFG, HIJK / LMNO, PQRS
    1234 / DEFG / PQRS
    ABCD / HIJK, DEFG / PQRS
    ABCD / STUV / LMNO

    So the formula I'm using is:

    =SUM(COUNTIFS(A1:A3,ABCD,B1:B3,"*DEFG*",C1:C3{"*LMNO*","*PQRS*"}))

    So for A, my first criteria is ABCD. In B, DEFG wherever it is in the cell. Provided those two criteria are met, I want LMNO or PQRS in C, and only to be counted once.

    I want my formula to return 2, and it seems like it's counting every instance in C giving me an incorrect number.

    For instance, a sheet I'm working on has 480 entries, meaning if every condition was filled, I should get (only) 480. I'm getting 486. I suspect the formula is double-counting. TIA for the help.

    Jim

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: COUNTIFS and multiple criteria per cell

    I don't fully understand the data set. I mean, by inspection I guess I get it, but it's just understanding by induction, it's not like there's any rules saying how long they are or whatever.

    Anyway the SUM(COUNTIFS()) looks logically correct, but there's a comma missing after the C1:C3 term in your example code.

    COUNTIFS with OR has shown up in the past, if you want to move to a SUMPRODUCT design or something.

    As it stands, your problem isn't really clear to me. Can you post an example worksheet?

  3. #3
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: COUNTIFS and multiple criteria per cell

    =COUNT(IF(A1:A3="ABCD",IF(ISNUMBER(SEARCH("DEFG",B1:B3)),IF((ISNUMBER(SEARCH("LMNO",C1:C3))+(ISNUMBER(SEARCH("PQrs",C1:C3)))),1))))
    Confirm COntrol+Shift+enter
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  4. #4
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: COUNTIFS and multiple criteria per cell

    Thank you for such prompt answers. To clarify, I want the formula to first look in A. If the formula finds the text I'm looking for, then move to B. B contains multiple (identical length) data separated by commas. Don't count 1 yet. If conditions 1 and 2 are met, go to C. C contains multiple (identical length) data separated by commas. If the formula finds -any- of the desired fields, count 1, even if multiple criteria are found in C. I suspect what I had before is making multiple counts.

    On a related note, when I'm pressing Ctrl-Shift-Enter, am I pressing those keys at the conclusion of me having typed out the entire formula? What I see happens is that curly brackets are entered at the beginning and end of the formula.

    RobertMika, also thanks for your input. The data is on a work computer, so I'll have to wait until I return to work to see if your suggestion works. I'll also have to look up the syntax of the formula you've provided. One last thing-- C may have as many as 10 criteria. I guess that's going to be a lot of closed parens. At any rate, thanks for the help. I'll let you know how it goes ("Solved" or not).
    Last edited by jimbosi; 11-26-2013 at 07:09 PM. Reason: Added comment about length of formula based on number of criteria in C.

  5. #5
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: COUNTIFS and multiple criteria per cell

    If you got multiple instances(10) it would be better to create a helper column (D) and then sum then up.
    If you add the curly brackets yourself Excel will indicate error.

  6. #6
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: COUNTIFS and multiple criteria per cell

    Tks for the feedback on Ctrl Shift Enter. With the helper column, the live sheet is about 800 records. For A, there are about 12 different terms. In B, there are about 200 potential terms. For C, where I need the OR that you used IF ISNUMBER, there are perhaps 10 potential terms. So for each A, I'm extracting a specific B coupled with A, contingent on whether a C condition is present. Make sense?

    I was hoping the COUNTIFS would work because of the relative simplicity. I ran your formula (thanks again!), and it appears to work on a test sheet I created at home. That sheet, however, is a fraction of the size and complexity of the live sheet.

    And as one last thing, I'm guessing it won't matter where in C that the sought-after string appears? The string can appear anywhere in the cell.

    TIA once again!

  7. #7
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: COUNTIFS and multiple criteria per cell

    It does not but if you got let say "PQRS" and your term to search is PQR you will get 1.
    Post your workbook to see what can be done.

    Please add reputation if you happy with solution.

  8. #8
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: COUNTIFS and multiple criteria per cell

    I tried the above array "=COUNT . . . " on my sheet. My issue is that for the third condition/column, there may be as many as 32 different values in a cell, and I may need to count as many as 12 of them (to equal 1 in this case). In other words, I'm checking the first column (A1:A3="ABCD" . . . ") and the second column (which may have several values among about 200, so multiple values may be in this column "(ISNUMBER(SEARCH("DEFG",B1:B3) . . . " So when the first two conditions are met . . .

    . . . the problem I'm having is the vast number of values that may be present in C1:C3 in relation to the values I'm searching for "(ISNUMBER(SEARCH("LMNO",C1:C3))+ . . . "

    Can I just keep adding "(ISNUMBER(SEARCH(" linked by a + sign to do an OR search on those several C column criteria? It could be easier if I had a lookup table, whereby I point the formula there, and if it makes a match between what's in the cell and what's in the table, count 1? TIA for the help.

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

    Re: COUNTIFS and multiple criteria per cell

    Hello jimbosi,

    If you put your 12 search values for column C in Z1:Z12 (you can choose any location but it needs to be a column) then you can use this array formula

    =SUM(IF(MMULT((A1:A10="ABCD")*ISNUMBER(SEARCH("DEFG",B1:B10))*ISNUMBER(SEARCH(TRANSPOSE(Z1:Z12),C1:C10)),(Z1:Z12<>"")+0)>0,1))

    That won't count any row more than once
    Audere est facere

  10. #10
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: COUNTIFS and multiple criteria per cell

    The formula works in that it reports accurate results-- thanks! Now I've run into another problem (with the formula). I keep getting the error "excel ran out of resources . . ." Dunno what to do about that. I figured having the helper columns would help keep the calculation overhead low. Guess not. Any ideas?

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

    Re: COUNTIFS and multiple criteria per cell

    How many rows are you using in the formula? If you are using whole columns that isn't a good idea, better to restrict to a specific range

  12. #12
    Registered User
    Join Date
    11-23-2013
    Location
    Washington DC
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: COUNTIFS and multiple criteria per cell

    You're exactly right. I changed the count to account for just top to bottom. The errors went away. I don't know of a quick way to determine the bottom-most row, so ordinarily I've just picked the entire column. I assess this thread as solved, and I heartily thank everyone who responded, and how quickly they did. As I grow in Excel competence, I'll try to pay it forward. Thanks again.

+ 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 multiple criteria in single criteria range
    By MCP313 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-01-2016, 03:51 AM
  2. [SOLVED] Multiple criteria on countifs
    By wayneg in forum Excel General
    Replies: 3
    Last Post: 11-01-2012, 07:17 AM
  3. Replies: 0
    Last Post: 07-27-2011, 01:00 AM
  4. SUM COUNTIFS with multiple criteria
    By john_london in forum Excel General
    Replies: 4
    Last Post: 02-28-2011, 11:35 AM
  5. COUNTIFs with multiple criteria
    By Cene K in forum Excel General
    Replies: 5
    Last Post: 10-28-2005, 06: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