How to count the number of times a column name appears AND that column has a nonblank cell

StackOverflow https://stackoverflow.com/questions/17263416

  •  01-06-2022
  •  | 
  •  

Question

I apologize if this is not a 100% clear description, but this is also why I'm asking it, because I'm not sure exactly how to phrase it to search for the answer (so far, fruitless).

I keep stats and records for my soccer team, including which players played against which teams, the results, etc. Right now I have Table 1 set up so that the player names are in columns A and B (first, last), and the column headers from thereon are the names of the teams we have played, listed chronologically (e.g. Team A, B, C, D, A, C, B, D, etc.). For every game I update that game's column for every player that played with a W, L or T (this enables me to calculate career win percentage per player, etc.).

In Table 2 I have the same A & B columns showing every player, and a condensed number of columns according to each team (i.e. Team A, B, C, D, etc.). What I want to do is set Table 2 up so I can show the number of games each player has played against each team, i.e. how many times there is a W, L or T in a given row for a any instance of a given team name in Table 1).

I was hoping something along the lines of this would work for the first player:

=COUNTIFS(Attendance!$B2:$BS2,'Players vs.   Teams'!C$2,Attendance!$C3:$BS3,OR("=W","=L","=T"))

Alas, it does not. I get a #VALUE! error back. My thought process was to count all cells that met two requirements:

  1. The team name in the first table matches the team name in the second table (e.g. Team A). There will be multiple instances.
  2. The cells in that player's row in the first table are nonblank (W,L or T) in columns corresponding to that particular team (Team A).

I know the first countif criteria works because if used independently, it returns the number of times a specified team has been played (i.e. is listed in Table 1). I can't figure out how to count the number of times that has happened and a particular player has a non-blank cell in one of those columns in Table 1. Any thoughts?.....

Was it helpful?

Solution

You can't use an OR function in COUNTIFS quite like that, try this approach....

=SUM(COUNTIFS(Attendance!$C$2:$BS$2,'Players vs. Teams'!C$2,Attendance!$C3:$BS3,{"W","L","T"}))

That specifically counts "W","L" and "T", but you could just count non-blanks with this version

=COUNTIFS(Attendance!$C$2:$BS$2,'Players vs. Teams'!C$2,Attendance!$C3:$BS3,"<>")

...and with the $ signs set correctly you should be able to copy that formula across and down.....

Edit: ranges were also mismatched sizes, now edited

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top