+ Reply to Thread
Results 1 to 20 of 20

Counting multiple criteria in multiple columns

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

    Counting multiple criteria in multiple columns

    I use the following array formula to count multiple criteria (for a list of criteria in a helper column, only count once):

    =COUNTA($B$2:$B$100)SUMPRODUCT(1(MMULT(TRANSPOSE(1(ISTEXT($D$2:$D$10))),1(ISERROR(SEARCH($D$2:$D$10,TRANSPOSE($B2:$B$100)))))=COUNTA($D$2:$D$10)))

    The data is in B:B, and the helper column is in D:D.

    I want to incorporate a second column, and if there is a criteria match in either column, then count 1. If I make the data B:C, the formula ends up counting twice, when I only want it to count once.

    How can I modify this formula, or is another (array) formula better suited to look at two (adjacent) columns, if it sees the criteria in the helper column, to only count once?

    TIA for the help!

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

    Re: Counting multiple criteria in multiple columns

    Hello Jim,

    The formula you posted is not correct, missing some symbols. Could you please attach a dummy file & explain the conditions with expecting result?
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

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

    Re: Counting multiple criteria in multiple columns

    {=COUNTA(A1:A8)-SUMPRODUCT(1*(MMULT(TRANSPOSE(1*(ISTEXT(F1:F2))),1*(ISERROR(SEARCH(F1:F2,TRANSPOSE(A1:A8)))))=COUNTA(F1:F2)))}

    The - before SUMPRODUCT and 1* was what I was missing.

    At any rate, I have two adjacent columns (represented here as A1:A8, but the real sheet would be A:B) in which I want to count values only once, which are derived from a helper column (F1:F2).

    I've previously used three columns; one counting 1 or 0 for A, one counting 1 or 0 for B, and a final column counting 1 if either previous column is 1.

    I was hoping to consolidate the sheet by only using one column (a la the above formula) to capture the two columns from which I want to count criteria and not have it duplicate; i.e., if I use the above formula and change A1:A8 to A1:B8, I'll get cumulative counts from both columns.

    I hope that makes sense. If not, I'm happy to provide further input. TIA for your responses!

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Hi.

    I think Haseeb meant more that you should attach an actual workbook.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

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

    Re: Counting multiple criteria in multiple columns

    Tks for your hint. Here's an attached workbook:

    Cheers!
    Attached Files Attached Files

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Thanks.

    And what's the expected result here, and why?

    Regards

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

    Re: Counting multiple criteria in multiple columns

    In the enclosed workbook, the correct count should be 6. My organization wants to count the percentage of criteria, of which multiple criteria qualifies, that meet a certain condition.

    To complicate things, the relevant criteria are maintained in two columns (I can't control this), and any of the criteria in the helper column (there are about 15 criteria in the live sheet) should only count as 1 across rows.

    Further, I want to avoid duplicates across the two columns in which any of the criteria may be met.

    Finally, there may be any number of values per column, separated by commas. So the values I'm looking for may be anywhere in a cell, again, across the two columns.

    It's preferable I include the values of the helper column into the formula (or array) itself, but it's not a show-stopper.

    Having the three columns works (yes/no in columns A and B, with column C counting 1 if A or B is 1, it's just very inelegant.

    I already have other columns counting other things, so I'm trying to be efficient, as the live sheet is over 30,000 rows.

    TIA for the help!

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Thanks. Two more questions:

    1) Is the criterion in F1 ("cirb") only to be searched for in column A? Likewise, is the criterion in F2 ("imd2200") only to be searched for in column B?

    2) Is there a possibility that these strings could occur as partial substrings within longer strings? For example, might there be entries within column A of e.g. "scirb", or "cirb2", which you would not wish to be considered for the count? Likewise, might there be entries in column B of e.g. "bimb2200", or "imb2200A", etc., again, which you would not wish to be considered for the count?

    Regards

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

    Re: Counting multiple criteria in multiple columns

    For your 1)--absolutely correct. there are only four-letter codes in one column, and in an adjacent column, codes that have three letters followed by four numbers.

    For the helper column, those are exact values, which may or may not be in the cells to be counted as partial values; i.e., the exact values but separated by commas.

    For instance, a cell might contain brub, cirb, temp -- I want the formula to count 1 for cirb in the cell. If the adjacent cell contains imd2200 (also in the helper column), then still ONLY count 1 (and not two for the two matches; cirb AND imd2200). Make sense?
    Last edited by jimbosi; 03-22-2015 at 11:18 AM. Reason: upper case

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Ok, but can you just confirm then that there is no possibility of any occurrences such as the examples I gave?

    Regards

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

    Re: Counting multiple criteria in multiple columns

    Apologies for the incomplete/confusing answer-- the four-letter values are unique, and there won't be any partial matches (more than two characters in a row in common) in the column with three-letter/four-number entries.

    I just want to count some four-letter entries (and not others), and some three-letter/four number entries (and not others), and not duplicate the count if matching criteria is found in both columns. In other words, even if there is a match from the helper column (which contains countable values found from both columns) in both columns, only count 1.

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Perhaps:

    =SUM(COUNTIFS(A:A,{"=","=","<>"}&"*"&F1&"*",B:B,{"=","<>","="}&"*"&F2&"*"))

    Regards

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

    Re: Counting multiple criteria in multiple columns

    Hmm . . .

    The helper column contains just over a dozen values, with perhaps three or four four-letter codes, while the remainder are three-letter/four-number codes.

    I can do the COUNTIFS, but the --- {"= . . . cell reference . . . "*", --- portion I'm repeating for every value, right? Whew, very long formula!

    I'll give your solution a shot on the live sheet when I return to work tomorrow. I'll let you know. Cheers!

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    I don't understand. There are only two values in your workbook.

    What's more, the range references F1 and F2 can be replaced with contiguous ranges of values, if required, simply changing the initial SUM to SUMPRODUCT.

    Regards

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

    Re: Counting multiple criteria in multiple columns

    My mistake for over-simplifying the values in the live sheet.

    Yes, there are several values in the helper column, some of which apply to column A (four-letter codes), while others column B (letter/number).

    It looks like this:

    abcd
    efgh
    igkl
    mnop
    zxy1200
    zxy1300
    zxy1400
    zxy1500
    zxy1600
    zxy1700
    zxy1800

    I've seen MMULT work in this case, but I haven't seen it for two columns. Still, cheers for your help!

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Sorry, but could you re-attach your workbook with a more realistic example, together with your expected result?

    Regards

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

    Re: Counting multiple criteria in multiple columns

    Here's a more accurate representation of the live sheet:

    I'll get my request right eventually. Tks for working with me!
    Attached Files Attached Files

  18. #18
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    Ok, now I think I understand.

    Can you test this array formula**?

    =SUM(N(MMULT(N(ISNUMBER(SEARCH(TRANSPOSE(F1:F3),A1:A8))),ROW(F1:F3)^0)+MMULT(N(ISNUMBER(SEARCH(TRANSPOSE(F4:F9),B1:B8))),ROW(F4:F9)^0)>0))

    Regards

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

    Re: Counting multiple criteria in multiple columns

    That looks fantastic. I use a similar array formula to extract one column's worth to count in exactly the same way.

    It works fine on the test data (I'm sure you wouldn't have sent it unless it did).

    I have never used the N function, so I guess I learned something new today.

    Tks for the education and helping me solve my issue. Problem solved! Cheers!

  20. #20
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting multiple criteria in multiple columns

    You're welcome! Glad we got there in the end!

    Cheers

+ 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. [SOLVED] counting cells/rows across multiple criteria (columns)
    By vf_guy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-19-2014, 10:06 PM
  2. [SOLVED] Counting multiple items with multiple criteria from multiple sheets?
    By essee in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-23-2013, 01:56 AM
  3. [SOLVED] Counting based on multiple criteria and columns
    By Big_R in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-17-2012, 10:43 AM
  4. Counting data with multiple criteria from different columns
    By Muammar in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-10-2012, 08:24 AM
  5. [SOLVED] Help w/ counting multiple columns based on IF criteria
    By ConstructionGuy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-08-2005, 12:10 AM

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