I am familiar with the =AVERAGE.WEIGHTED
function in Google Sheets, but I'm wondering if there's a way to add an IF in there, like =AVERAGEIF
. I have a baseball spreadsheet, with the following columns:
Column A – Player Name, Column B – Team, Column C – Innings Played, Column D – Batting Average
Basically, I want a weighted average of batting averages of all players on certain team, using innings played as the weights. If I used =AVERAGE.WEIGHTED(D:D, C:C)
, I would get a nice weighted average of all batting averages with innings played as the weights, but I only want to include players who have a Team of Yankees. How could I go about this?
Thanks in advance!
Best Answer
I actually found one way to accomplish this! I added a Column E which is Innings Played multiplied by Batting Average (
Column C * Column D
). Then, I can use a=SUMIF
to sum results in column E if Column B shows a certain team, and divide that by another=SUMIF
that sums Column C if Column B shows that same team.=SUMIF(B:B, "Yankees", E:E)/SUMIF(B:B, "Yankees", C:C)
. Just wanted to post this answer in case anyone else is looking for the same thing!