# Act on the last (n) number of rows

Grouping & More

### #1 JPK1066

JPK1066

• Members
• 101 posts

Posted 09 October 2017 - 07:40 PM

I will attach a piece of a WS that is 1 of 30 identical WS's that I use Grouping technique on. The sheets get updated daily as games get played but unfortunately teams will be a different junctures. Some will be playing their 30th game while others will be playing their 32nd. I would like to be able to use an average function on the last three games played, or perhaps two. How can I create a query that will draw on the last (n) of games from identically formatted WS's that are at different counts?

TY

JPK1066

### #2 Jonathan

Jonathan

• 887 posts

Posted 10 October 2017 - 11:47 PM

Hi JPK,

You can do this by using a table along with the COUNTA function to discover how many records are in the table. You can then use the OFFSET function to extract the last 3 records.

You can see how to create a table in the video lesson: Expert Skills Lesson 1-11 Convert a range into a table and add a total row.

The COUNTA function and OFFSET functions are covered in the video tutorial: Expert Skills Lesson 4-6 Create dynamic formula-based range names using the OFFSET function.

The formula to calculate how many records are in the table will look like this:

=COUNTA(Table1[Column1])

To extract the last 3 records in the table, the formula becomes:

=OFFSET(B4,COUNTA(Table1[Column1])-3,0,3)

Now you can average the values by simply adding an AVERAGE function, creating the final formula:

=AVERAGE(OFFSET(B4,COUNTA(Table1[Column1])-3,0,3))

I have attached a copy of your workbook with the formulas applied:

I hope this is the solution you were looking for, but please feel free to reply if you need any more help with this.

Jonathan is part of the professional team who answer Excel-related questions posted on the ExcelCentral.com forums.
Jonathan also tests our courses prior to publication and has worked on all of our ten world bestselling Excel books for Excel 2007, Excel 2010, Excel 2013, Excel 2016 for Windows and Excel 2016 for Apple Mac. Jonathan has also worked on over 850 video lessons for or video courses covering Excel 2007, Excel 2010 and Excel 2013.
As well as extensive Excel knowledge, Jonathan has worked in the IT world for over thirteen years as a programmer, database designer and analyst for some of the world's largest companies.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users