+ Reply to Thread
Results 1 to 14 of 14

Thread: Counting Groups with Formula that meet a criteria

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Counting Groups with Formula that meet a criteria

    I'm using Excel 2003 and would like a formula to identify the number of distinct groups that meet a criteria. For example, in the following data I would like to know the number of people whose aggregate amounts exceed a total of 10 (2 people, Jim with a total of 11 and Dave with a total of 15 qualify, Bob with a total of 9 does not. Is there a formula to get the distinct number based on a criteria in a separate range? Here's the data for the example.


    Name Amount
    Bob 5
    Jim 9
    Dave 15
    Jim 2
    Bob 4
    Last edited by PCJasper; 11-29-2011 at 02:56 PM.

  2. #2
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Counting Groups with Formula that meet a criteria

    Hello & Welcome to the Board,

    How about a pivot table?

    Row Labels >> Name
    Values >> Amount (Sum)

    Then on the Row Lables filter to > 10
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  3. #3
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Counting Groups with Formula that meet a criteria

    If you need an actual count using formulas...

    Assuming data in A2:B6, then in C2:

    =IF(COUNTIF(A$2:A2,A2)=1,IF(SUMIF($A$2:$A$6,A2,$B$2:$B$6)>10,1,0),0)

    copied down

    and final count is:

    =SUM(C2:C6)
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  4. #4
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    I was hoping for a solution with a single formula. Essentially I've got a pivot table where the columns represent a series of days and the rows represent actions that a person takes during the day. The values are the number of times an action is performed. I was hoping for a formula where I could determine the number of people that were active each day. My example was an attempt to simplify the problem to a single day. Does this make sense? I could provide a multi-day example if that would help.

  5. #5
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Counting Groups with Formula that meet a criteria

    Quote Originally Posted by PCJasper View Post
    My example was an attempt to simplify the problem to a single day. Does this make sense? I could provide a multi-day example if that would help.
    This may make sense to NBVC as he is exceptional with formulas, but examples always help to ensure you hopefully get the proper results the first time.
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  6. #6
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    Perhaps this will clarify the issue. Imagine you have people visiting a site at multiple times over a period of days. Each visit is recorded along with a user's activity for each day of the period. I'm hoping for a formula that would record the number of visitors each day recognizing that a visitor might be recorded with multiple activities for any given day. Here's how the data might look:

    Name, Code, Day1, Day2, Day 3
    Joe, A,0,0,3
    Joe, B,1,0,0
    Dave,A,0,0,1
    Dave,C,0,1,1

    In this example, the formula would calculate 1 visitor on Day 1 (Joe activity B), 1 visitor for day 2 (Dave activity C) and 2 visitors on day 3 (Joe Activity A which he performed 3 times and Dave Activity C).

    Thanks in advance to anyone who might help. This is my first post and I apologize for any confusion.

  7. #7
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Counting Groups with Formula that meet a criteria

    Assuming that table is in A1:E5, incl. headers, then in C7, for Day1, try,

    =COUNT(1/FREQUENCY(IF(C$2:C$5>0,IF($A$2:$A$5<>"",MATCH($A$2:$A$5,$A$2:$A$5,0))),ROW($A$2:$A$5)-ROW($A$2)+1))
    confirmed with CTRL+SHIFT+ENTER not just ENTER and copy across.

    Is that what you needed?
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  8. #8
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    That was Great and exactly what I was looking for. Thank you so much I was wresting with that for several days. This might need to be a new thread but is there a way to utilize that formula as part of a subtotal so that only the filtered results are included in the count?

  9. #9
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Counting Groups with Formula that meet a criteria

    Try:

    =SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET($A$2,ROW($A$2:$A$5)-ROW($A$2),0)),IF(C$2:C$5>0,MATCH($A$2:$A$5,$A$2:$A$5,0))),MATCH($A$2:$A$5,$A$2:$A$5,0)),1))
    confirmed with CTRL+SHIFT+ENTER and copied across.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  10. #10
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    Your solution worked great and I have successfully adapted it to my spreadsheet. The only problem left is that the sheet is driven from an access query which produces different data each day with the total number of rows varying. I can calculate the last Row and place it in a cell named ARows. Could I use an indirect or address reference in the formula you provided to incorporate this reference so that I wouldn't have to modify my formula each day? For example, assume ARows contains the calculated value 5. How could I use this calculated value instead of the constant 5 in the formula?

  11. #11
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Counting Groups with Formula that meet a criteria

    You can replace all the $5 with an INDEX reference.

    for example

    ROW($A$2:$A$5)

    would change to:

    ROW($A$2:INDEX($A:$A,ARows))

    and

    IF(C$2:C$5>0...

    would change to:

    IF(C$2:INDEX($C:$C,ARows)>0
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  12. #12
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    That works with the exception of one reference. In this formula ARows equals 229. Here are the two renditions. First the one that works:

    =IF(AND(G9>0,G10>0),SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(G13,ROW($B$13:$B$229)-ROW($B$13),0)),IF(G$13:INDEX(G:G,ARows)>0,MATCH($B$13:INDEX($B:$B,ARows),$B$13:INDEX($B:$B,ARows),0) )),MATCH($B$13:INDEX($B:$B,ARows),$B$13:INDEX($B:$B,ARows),0)),1)),"")

    To make it work I left the reference OFFSET(G13,ROWS($B$13:$B$229)-ROW($B$13)

    If I change it as follows I get "The Formula contains and error" and the Index after the 13: is highlighted.
    "=IF(AND(G9>0,G10>0),SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(G13,ROW($B$13:INDEX($B:$B,ARows))-ROW($B$13),0)),IF(G$13:INDEX(G:G,ARows)>0,MATCH($B$13:INDEX($B:$B,ARows),$B$13:INDEX($B:$B,ARows),0) )),MATCH($B$13:INDEX($B:$B,ARows),$B$13:INDEX($B:$B,ARows),0)),1)),"")

    Any idea why this reference does not work?

  13. #13
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Counting Groups with Formula that meet a criteria

    It is because you now have too many nested functions in XL2003. If you take out the IF() part, it works fine.. You can hide the error by conditionally formatting the cell to give white font with formula: =ISNA(X1) where X1 is topleft most cell you chose for formatting.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  14. #14
    Registered User
    Join Date
    11-17-2011
    Location
    Jasper, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Counting Groups with Formula that meet a criteria

    You're right about too many threads for Excel 2003. That also explains why it worked when I tried each part on its own. Thanks so much for all your insight.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0