+ Reply to Thread
Results 1 to 12 of 12

Count # of cells based on multiple Criteria

  1. #1
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Count # of cells based on multiple Criteria

    Hello,

    I am having issues using IF and COUNT statements. What I am trying to do is use the Player Stats tab as a raw overview screen which sums together the values in the Raw Data tab.

    My current question is for the Games Played column in the This Tournament section of the Players tab. The logic I am going with is:
    On the Raw Data tab, If tournament# = 1 and If Player Name in column B or C matches the name from column A on the Player Stats tab
    Then count for that row under columns E through J on the Raw Data tab, the number of cells with a value >=21

    The idea is to repeat this logic across all rows against the raw data tab, based on the attached file, I would expect the count for Billy to appear as 3. I feel like I am missing something very simple.

    Thank you in advanced for your help. I am looking forward to your responses.

    test file.xlsx

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Count # of cells based on multiple Criteria

    You don't say in your profile what version of Excel you are using. But, on the basis of the file extension, I assume it is 2007+.

    In that case, you should use COUNTIFS, not IF and COUNTIF



    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Count # of cells based on multiple Criteria

    Quote Originally Posted by TMS View Post
    You don't say in your profile what version of Excel you are using. But, on the basis of the file extension, I assume it is 2007+.

    In that case, you should use COUNTIFS, not IF and COUNTIF

    Regards, TMS
    My apologies. I updated my profile to reflect the current version. I am using excel 2013.

    When using the COUNTIFS, am I able to reference another cell in the criteria section? I was able to get the first criteria to work, however the second one is producing a #Value.

    =COUNTIFS('Raw Data'!A2:A99999, "=1",'Raw Data'!B2:C99999, "='Player Stats'!A3")

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Count # of cells based on multiple Criteria

    Maybe like this

    =COUNTIFS('Raw Data'!A2:A99999, "1",'Raw Data'!B2:C99999, "Billy Kopec")
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Count # of cells based on multiple Criteria

    I get the same #VALUE! result. In addition I tried it with a = inside the "" as well. I attempted that based on Microsoft's page. It seems like I am missing something simple.
    http://office.microsoft.com/en-us/ex...010047494.aspx

  6. #6
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Count # of cells based on multiple Criteria

    Actually I just may have figured it out. The COUNTIFS cannot expand over multiple columns. In the second criteria I had it matching B and C. I guess I will have to create multiple countifs to resolve. I will post again if I hit more issues.

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Count # of cells based on multiple Criteria

    Quote Originally Posted by SpikeyMuscle View Post
    The COUNTIFS cannot expand over multiple columns.
    Sure it can

    =COUNTIF(A1:D5,"Billy Kopec")

    A
    B
    C
    D
    E
    1
    Billy Kopec
    2
    Billy Kopec
    3
    3
    4
    Billy Kopec
    5

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count # of cells based on multiple Criteria

    Quote Originally Posted by SpikeyMuscle View Post
    The COUNTIFS cannot expand over multiple columns.
    Sort of. All the range references have to be the same dimensions. You have 1 range referring to a single column and another range referring to 2 columns.

    Try it like this:

    =SUMPRODUCT(--('Raw Data'!A2:A99999=1),SIGN(('Raw Data'!B2:B99999='Player Stats'!A3)+('Raw Data'!C2:C99999='Player Stats'!A3)))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  9. #9
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Count # of cells based on multiple Criteria

    Thanks everyone for your responses. It has helped me populate a great portion of the excel statistics, however I have hit another road block. Please find the updated file.

    test file2.xlsx

    I am currently stuck on column I of the Player Stats tab. The logic I currently have is as follows:

    =COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$C$2:$C$99999,A3,'Raw Data'!$F$2:$F$99999,">=21",'Raw Data'!$F$2:$F$99999,">" & 'Raw Data'!$G$2:$G$99999)
    +COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$C$2:$C$99999,A3,'Raw Data'!$H$2:$H$99999,">=21",'Raw Data'!$H$2:$H$99999,">" & 'Raw Data'!$I$2:$I$99999)
    +COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$C$2:$C$99999,A3,'Raw Data'!$J$2:$J$99999,">=21",'Raw Data'!$J$2:$J$99999,">" & 'Raw Data'!$K$2:$K$99999)
    +COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$D$2:$D$99999,A3,'Raw Data'!$G$2:$G$99999,">=21,'Raw Data'!$G$2:$G$99999,">" & 'Raw Data'!$F$2:$F$99999")
    +COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$D$2:$D$99999,A3,'Raw Data'!$I$2:$I$99999,">=21",'Raw Data'!$I$2:$I$99999,">" & 'Raw Data'!$H$2:$H$99999)
    +COUNTIFS('Raw Data'!$B$2:$B$99999,$P$1,'Raw Data'!$D$2:$D$99999,A3,'Raw Data'!$K$2:$K$99999,">=21,'Raw Data'!$K$2:$K$99999,">" & 'Raw Data'!$J$J:$H$99999")

    Although this seems daunting, it mainly works, however the 4th criteria definition where I am attempting to compare two identical ranges is where all results end up as 0. The logic of each step is:

    Criteria 1 = Is the tournament the current tournament, controlled by column B
    Criteria 2 = Does the player name in column C or D in the raw data section match the player name on the players tab
    Note: If player name is in column C, then that players scores would be entered in F, H, J
    If player name is in column D, then that player's scores would be entered in G, I, K
    Criteria 3 = Is the corresponding cell >=21
    These first three criteria work, however I need a 4th criteria that takes into account if a score goes into extra points in which case, the value in each column need to be compared. This leads to Criteria 4. Columns F and G is game 1. H and I is game 2, and J and K is game 3.

    Criteria 4 = The value in one cell must be larger than another cell.
    For example, the 'Raw Data'!$I$2:$I$99999,">" & 'Raw Data'!$H$2:$H$99999) is stating (I think), for each line, if cell I# > than cell H# then count.

    However my logic for Criteria 4 always returns a result of zero which is incorrect. Instead BK should return a games won result of 1 and DG should return a result of 2.

    Thanks so much for taking the time to look into this!

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count # of cells based on multiple Criteria

    I didn't download your file.

    With the COUNTIFS function, you can't do this:

    'Raw Data'!$F$2:$F$99999,">" & 'Raw Data'!$G$2:$G$99999

    The criteria has to be a single element. something like this:

    'Raw Data'!$F$2:$F$99999,">" & 'Raw Data'!$G$2

    See if this does what you want:

    =SUMPRODUCT(--('Raw Data'!$B$2:$B$99999=$P$1),--('Raw Data'!$C$2:$C$99999=A3),--('Raw Data'!$F$2:$F$99999>=21),--('Raw Data'!$F$2:$F$99999>'Raw Data'!$G$2:$G$99999))

    On a side note...

    Do you actually have data down to row 99999? The SUMPRODUCT function will evaluate EVERY cell referenced. Each of your ranges is almost 100,000 cells times 5 ranges = 500,000 cells being evaluated just for this one formula.

    If your data is less than 99999 rows you should use smaller ranges.

  11. #11
    Registered User
    Join Date
    06-11-2014
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Count # of cells based on multiple Criteria

    Thanks Tony. That solved it. What I did was created a variance section and then used a value of ><0 based on the criteria I was looking for to pull in the data needed.

    Thank you to everyone who help. I will make this as resolved.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Count # of cells based on multiple Criteria

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count # of cells based on multiple Criteria

    Good deal. Thanks for the feedback!

+ 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] Count occurances based on very specfic criteria from multiple cells (excel 2003)
    By Ash Ford in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-10-2013, 09:02 AM
  2. [SOLVED] Count without duplicates based on multiple criteria from different cells
    By perryadam in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-23-2013, 12:54 PM
  3. Replies: 6
    Last Post: 11-11-2012, 12:40 AM
  4. Replies: 1
    Last Post: 11-20-2010, 05:38 AM
  5. Count number of cells based on multiple criteria
    By Cumberland in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-11-2007, 11:28 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