+ Reply to Thread
Results 1 to 6 of 6

Count number of rows with multiple criteria

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    Copenhagen, DK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Count number of rows with multiple criteria

    Hi!

    Hope someone can help me with this issue ... First, a description of my dataset:

    Column A: Dates (30 days)
    Row 1: Names of students (100 names in column B to CW)
    Row 2: Each students age
    Row 3: A notice of whether the student is internal or external.

    Range (B4:CW33) : A number of classes the student has attended (0-?)

    Ex.

    Name John Brian Danny Eric
    Age 21 22 21 23
    Type Int Ext Ext Ext

    Date
    21. 0 0 0 0
    22. 2 0 2 1
    23. 0 1 0 0
    24. 0 0 0 0
    25. 0 2 1 1
    26. 4 2 0 2
    27. 0 0 0 2

    Now the calculation:

    In a cell I want to count the number of rows (dates in column A) where there are at least one student with a positive number of classes, and meting a criteria of age and internal/external.
    Ex. for the criteria (Age = 21) and (Type = Ext) the result is 3 (dates 22, 25 and 26).

    How is that possible within the SUMPRODUCT formula?

    Thanks!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Count number of rows with multiple criteria

    If you want me to test this, click GO ADVANCED and use the paperclip icon to post an actual workbook.

    The SUMPRODUCT() construct you want goes like this:

    =SUMPRODUCT(--(FirstRange=FirstVal), --(SecondRange=SecondVal))

    You could add a 3rd the same way. Resist the urge to use whole columns for your ranges.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-16-2010
    Location
    Copenhagen, DK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Count number of rows with multiple criteria

    Thanks, I've tried to post a workbook with test data. Can't figure out how to count the rows where at least one column matches the criteria (not calculating the sum)

    TestData.xlsx

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

    Re: Count number of rows with multiple criteria

    Based on your example:

    =SUMPRODUCT(($B$2:$P$2=$C$37)*($B$3:$P$3=$C$36)*SIGN(SUBTOTAL(9;OFFSET($B$4;ROW($B$4:$B$33)-ROW($B$4);COLUMN($B$4:$P$4)-COLUMN(B4)))))

    where C36 holds "Ext" & C37 holds 21.

    translate SUMPRODUCT, SIGN, OFFSET, ROW & COLUMN as and if appropriate (SUMPRODUKT, FORTEGN, FORSKYDNING, RĘKKE & KOLONNE)
    Last edited by DonkeyOte; 09-17-2010 at 05:21 AM.

  5. #5
    Registered User
    Join Date
    09-16-2010
    Location
    Copenhagen, DK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Count number of rows with multiple criteria

    Thanks for the reply - Almost there now

    The problem is if there is more than one column matching the conditions in a row, than the number of values are counted - not only the number of rows.
    If I put a number greater than 0 in cell O33, the result for Age=21/Ext with the formula gives 5, but I was hoping for 4 = the count of rows (7, 24, 29 and 33)

    Can this be solved?

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

    Re: Count number of rows with multiple criteria

    Try this "array formula"

    =SUM(IF(MMULT(IF(ISNUMBER(B4:P33);B4:P33,0);TRANSPOSE((B2:P2=C37)*(B3:P3=C36)));1))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

+ 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