Jul 15, 2024

Running average

Hi, 

I have trouble calculating a running average in Google sheets. 

Please see the attached file. 

In cell H2, I want to calculate the last 3-games average GD for the team at cell G2.

So I need a formula that finds the last 3 rows that had the team name in G2 in columns B and C (you could also select those rows with the most recent data for example) and then take the Home GD value if Home = G2 or take the Away GD value if Away = G2. We take the sum of hose three values and then divide by 3. This is the formula I need in cell H2.

For example for Fire this would give us (3-4-1)/3 = -0.667
Locked
This question is locked and replying has been disabled.
Community content may not be verified or up-to-date. Learn more.
Recommended Answer
Jul 17, 2024
The easiest way is to remove the "limit 3" from the QUERY function like this:

=AVERAGE(QUERY(VSTACK(CHOOSECOLS(A:E,1,2,4), CHOOSECOLS(A:E,1,3,5)), "select Col3 where Col2 = '"&G2&"' order by Col1 desc limit 3",0))

=AVERAGE(QUERY(VSTACK(CHOOSECOLS(A:E,1,2,4), CHOOSECOLS(A:E,1,3,5)), "select Col3 where Col2 = '"&G2&"' order by Col1 desc",0))

I hope this helps.
Original Poster Popov Siemens marked this as an answer
Helpful?
Recommended Answer
Jul 15, 2024
Hi Popov Siemens,
 
Thank you for the sample file!  I have placed a possible solution for you in the sheet/tab called Help, which I have added to your file.

I hope this helps!
 
Adam
Diamond PE Docs volunteer
Silver PE Classroom volunteer
Cert. Educator 1 & 2
Cert. Trainer
(not a Google employee)
 
When you've received a response that answers your question, please observe these forum courtesies:
 • If you had a Sheets problem, leave your demo sheet shared as View Only as part of this solution's archive,
 • Click Recommend on the post that best addressed your question, and
 • Post again soon!

Original Poster Popov Siemens marked this as an answer
Helpful?
All Replies
Jul 15, 2024
Hi Popov Siemens,
 
We would like to help you with this but because there are so many variables that can affect your results, we need to see a sample of your problem.  Would you please take a look at this post about Best Practices When Asking a Question and share a sheet that has the permissions set for “Anyone with link can EDIT”.  For the forum volunteers to help you better, we need to see clear explanations and examples of what you need to occur.  These examples do not require you to use formulas; just manually enter the data as it should appear.  Thanks!
Jul 17, 2024
You're welcome.
Jul 20, 2024
Hi again, 

Thank you for the invaluable help so far. I have another small request. 

I created a new sheet in the same place (Sheet2) https://docs.google.com/spreadsheets/d/1xzcZHRuS5vNNXF8Q-j5ft44fH3uc4E2NAbLtTlJvGLU/edit?gid=1182165271#gid=1182165271 .

I want to create (for each team in G3) the average GD over their last 3 games for each of their occurences. For example if a team played only once the value at H3 would be 0, if it played only 2 times, the value at I3 would be 0, if the team played 3 times, then the value at J3 should be (0-1-4)/3. if the the team played 4 times, then we take the last 3 values so = (-1-4+3)/3 etc. 

So could you help me create a formula that populates cells H3 to L3?

Thank you in advance!!!


false
5448372046443135548
true
Search Help Center
true
true
true
true
true
35
Search
Clear search
Close search
Main menu
false