+ Reply to Thread
Results 1 to 23 of 23

Countif with same criteria in multiple columns

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Countif with same criteria in multiple columns

    So I've got a spreadsheet for my football team which shows stats for the players over the season. I've recently started noting what positions people play, and I want to be able to filter the stats by the position. The challenge is that some people play multiple positions over the course of a match, so I've ended up with several columns for the position played.

    The below picture is some test data which I've simplified. As you can see, if I put "Primary" and "LB, it correctly pulls 6 matches for Alex and 0 for Tim. What I want is to be able to put "Any" and "LM" and it to return the 3 matches which Alex played at LM. I found a previous thread where Sum and Mmult were used but I couldn't figure out how to get something like that to work with my data. I've attached the original sheet for reference.
    sample.PNG
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Administrative Note:

    Is your forum profile showing the Excel PRODUCT that you need this to work for?

    Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.

    The three most recent Excel products are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    The screenshot I posted is from a google sheet for convenience, but I have updated my profile as I'm currently on 365 version 2302. Thanks.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    So this is for Excel - yes?

    Can you fill in expected results in the workbook itself? It's easier for us than working from a screenshot.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Actually, I think this might do what you want if indeed it is for Excel:

    =SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9="Win")*((FILTER($F$2:$H$9,$F$1:$H$1=$A$11)=$B$11)))

  6. #6
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    So this is something I've tried previously. It works for checking each column individually but not for checking all the columns at the same time unfortunately. I want to have the option to put "Any" in A11 and it return the correct number of wins based on the position in B11

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,176

    Re: Countif with same criteria in multiple columns

    Maybe like this

    =SUMPRODUCT(($A$2:$A$9=$A13)*MMULT(--($F$2:$H$9="LM"),{1;1;1}))

  8. #8
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    This is closer but it just returns the number of times the position is mentioned over columns F to H. I need it to be checking column C for the result before it looks in F:H

  9. #9
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,176

    Re: Countif with same criteria in multiple columns

    Try change to:

    =SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9=B$12)

    *IF($A$11="any",MMULT(--($F$2:$H$9=$B$11),{1;1;1}),INDEX($F$2:$H$9,0,MATCH($A$11,$F$1:$H$1,0))=$B$11))

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    This?

    =SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9="Win")*MMULT(--($F$2:$H$9="LM"),{1;1;1}))

  11. #11
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    Ah yeah I can make that work. I've amended it to if A11=Any then do that formula, else do your original formula which covers both scenarios. I also want to have the goals for and goals against columns update based on the selected position but I'm not sure I fully understand what MMULT is doing here to be able to apply it. I'll start reading up on it now but if you have a straightforward explanation for this scenario it would be really appreciated!

  12. #12
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    Quote Originally Posted by AliGW View Post
    This?

    =SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9="Win")*MMULT(--($F$2:$H$9="LM"),{1;1;1}))
    Apologies, it was this which seems to be in the ballpark of what I'm trying to do. I've adjusted the formula in B13 to =if($A$11="Any",SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9="Win")*MMULT(--($F$2:$H$9=$B$11),{1;1;1})),SUMPRODUCT(($A$2:$A$9=$A13)*($C$2:$C$9="Win")*((FILTER($F$2:$H$9,$F$1:$H$1=$A$11)=$B$11)))) which currently works and I can amend "Win" to "Draw" and "Loss" for the other columns. I don't really understand how MMULT is working here though if you're able to clarify.

    I did read through the forum rules although it doesn't mention how to reply. I'm assuming I should be using "Reply with Quote" so hope that makes it easier. Sorry, it's been forever since I've used this type of Forum! Thank you for your help

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. No help to be offered until you provide a link or, for members with fewer than 10 posts, a comment telling us where else you have posted this query.)

  14. #14
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    Ah apologies, I had missed that! Thanks for pointing out. I've only posted 2 other places - https://www.mrexcel.com/board/thread.../#post-6184879 and https://chandoo.org/forum/threads/co...columns.57086/

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Are you not aware that this rule exists on all three forums?

    Thanks for the links.

  16. #16
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    I wasn't, no. I mostly muddle by on my own but when I've had a query I've posted to MrExcel and generally had success so I've never crossposted before, but my original query on this issue didn't really get much traction hence the cross posting now. I'm in the process of updating my other posts as well.

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Which of us are you talking to?

    Make sure you share this solution on the other forums.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    I still don't know whom you were addressing in post #14.

    Do please have a read through the forum rules.

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    No need to use Reply with Quote - just say whom you are addresing, e.g. @AliGW.

    =MMULT(--($F$2:$H$9=$B$11),{1;1;1})

    MMULT(...,{1;1;1})

    simply tells Excel to look at all three columns and return 1 if the lookup value in B11 is found in any of them.

    If you change it to this:

    =MMULT(--($F$2:$H$9=$B$11),{1;2;3})

    and paste the formula into B16, you will get this:

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    B
    16
    1
    17
    1
    18
    1
    19
    2
    20
    1
    21
    1
    22
    1
    23
    1
    Sheet: Sheet1

    It's returning 1 for the value if it's found in column F and 2 if it's found in column G. If the value is found in multiple columns, it will return a sum of thoe values, so if it were found in all three, you'd get 1+2+3 which is 6.

    Does this help?

  20. #20
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    @AliGW I think that makes sense to me. Effectively MMULT is turning whether or not the text at B11 is in any of columns F:H into an integer right?

    So sumproduct here is saying "Sum the instances where Column A matches player name, multiplied by the instances where column C is a Win, multiplied by {1} if B11's value is found in any of columns F:H" ?

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Yes - that's about it - the MMULT is acting as three columns in one.

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  22. #22
    Registered User
    Join Date
    08-20-2015
    Location
    London
    MS-Off Ver
    365 version 2302
    Posts
    22

    Re: Countif with same criteria in multiple columns

    Amazing, thanks so much. I've figured out the Goals For and Goals Against on my own, now to figure out how to incorporate this into the actual sheet! I've marked as solved and had actually already added reputation I'll update the threads on the other sites now too. Thanks so much for your time!

  23. #23
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Countif with same criteria in multiple columns

    Great. Good luck!

+ 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. Countif using criteria in multiple columns
    By vesterholt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-10-2014, 03:20 PM
  2. CountIf Multiple criteria and columns
    By extko1 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-05-2013, 12:35 PM
  3. COUNTIF with multiple criteria and columns
    By burtonlang in forum Excel General
    Replies: 2
    Last Post: 04-10-2013, 05:43 AM
  4. [SOLVED] trying to do a "countif" with multiple ranges and multiple criteria. Countif, Sumproduct?
    By completelyhis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2013, 06:12 PM
  5. [SOLVED] COUNTIF with multiple criteria on several columns (different column heading)
    By rose4emi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2012, 06:41 AM
  6. Countif with criteria in multiple columns
    By syoung236 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-03-2012, 05:10 PM
  7. Replies: 8
    Last Post: 02-10-2009, 08:56 AM
  8. Countif - Two Criteria in two columns are met.
    By samprince in forum Excel General
    Replies: 12
    Last Post: 06-28-2006, 11:58 AM

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