+ Reply to Thread
Results 1 to 35 of 35

Formula to show Average of the last 'N' values in a row.

  1. #1
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Formula to show Average of the last 'N' values in a row.

    Hi,

    I need a formula to show the Average of the last 'N' values in a row. The row will be dynamically expanding. It is a database where the first column is a list of names. Each successive column represents an event where every person might be assigned a number. I want a formula to show for each person the average of their last 'N' non-blank values.

    Can anyone help me out?

    Edit: In the sample workbook what is needed is a formula in D2 to show the average of the last "N" values in the row starting from E2.
    Attached Files Attached Files
    Last edited by XLHell; 05-19-2022 at 03:20 AM. Reason: Added File

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,453

    Re: Formula to show Average of the last 'N' values in a row.

    Hi
    as members tailor their answer to the Excel version, please add your version to your profile as it only states "Excel" ( which is obvious here). Thx

  3. #3
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    Hi, I've done this thanks.
    Last edited by AliGW; 05-17-2022 at 05:36 AM. Reason: PLEASE don't quote unnecessarily!

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

    Re: Formula to show Average of the last 'N' values in a row.

    Last 'N' in a ROW or a COLUMN???

    Where in the sample workbook have you provided some expected results?
    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.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I'm not sure what formula to use. I want the results to be in Column 'D' which currently has a simple average formula because I don't know how to get the formula I want.

    I want the average of the last 'N' values in the row.

    This is a database that will dynamically expand and will have thousands of rows and columns.

    The first column is the names of the people. The following columns (barring sample, Count, average etc) will be events where some of the people will be assigned a numerical score. I want the average of the last 'X' scores that have been assigned, for each person.
    Last edited by AliGW; 05-17-2022 at 05:45 AM. Reason: PLEASE don't quote unnecessarily!

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

    Re: Formula to show Average of the last 'N' values in a row.

    Please mock up some expected results in your workbook. It will be much easier for us if the sample data is not all number 10!!!

    You do not need to know what formula to use, but surely you know what results you are expecting in the sample file? I just want you to add 10-15 rows in the workbook. Understand?

  7. #7
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    Thanks so much for the help, and apologies for being a bit slow. I've added several rows now. If I want the average of the last 20 values (this should be 30.95) I want to know the formula to input.
    Last edited by AliGW; 05-17-2022 at 05:54 AM. Reason: PLEASE don't quote unnecessarily!

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

    Re: Formula to show Average of the last 'N' values in a row.

    Firstly, you have removed the workbook and not replaced it - please reshare the amended workbook.

    Secondly, there is NO NEED to keep quoting the post before your own - plaese stop doing so, as it is a waste of space. Thanks.

  9. #9
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I know I'm trying to get it back, it shows as uploaded but keeps disappearing as soon as I close the window.

  10. #10
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    Sorry I forgot to save the changes. The correct version is up now.

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

    Re: Formula to show Average of the last 'N' values in a row.

    OK - thanks. This will help, but I have run out of time (need to get out into the garden). Someone else will advise.

  12. #12
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    Bumping this since I haven't received any suggestions. Can someone help me out please?

  13. #13
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Formula to show Average of the last 'N' values in a row.

    I don't understand what you want.

    Plese specify which cell you want the result and what is the result in that cell.


    Regards.

    Note : You're already put AVERAGE() in D2 , so I think D2 is the cell you want the result to display.
    But I don't know what is the value in D2 you want.

  14. #14
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    The value I want is the average of the last 'N' non-blank values in the row.

    For example if I want the average of the last 20 values, it should be 30.95. I don't know what formula to use to get that result.

  15. #15
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Formula to show Average of the last 'N' values in a row.

    Quote Originally Posted by XLHell View Post
    the last 'N' non-blank
    I'm still don't understand , AVERAGE() calculate from non-blank cells already.
    Please specific the result value in your file.

    Regards.

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

    Re: Formula to show Average of the last 'N' values in a row.

    In your sample file, in the first row of sample data, please show us how you calculated 30.95. Highlight the cells you used for this. I cannot get the last 20 non-blank cells to calculate that number however hard I try.

  17. #17
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Formula to show Average of the last 'N' values in a row.

    Hmmm,

    Please try

    D2
    =AVERAGE(INDEX(2:2,1,IFERROR(AGGREGATE(14,6,COLUMN($E2:INDEX($E2:$XFD2,1,AGGREGATE(14,6,COLUMN(E2:XFD2)/(E2:XFD2<>""),1)-COLUMN(E2)+1))/($E2:INDEX($E2:$XFD2,1,AGGREGATE(14,6,COLUMN(E2:XFD2)/(E2:XFD2<>""),1)-COLUMN(E2)+1)=""),1)+1,COLUMN(E2))):
    INDEX(2:2,1,AGGREGATE(14,6,COLUMN(E2:XFD2)/(E2:XFD2<>""),1)))

    Regards,
    Last edited by menem; 05-19-2022 at 02:27 AM. Reason: Edit formula

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

    Re: Formula to show Average of the last 'N' values in a row.

    That returns 19.75 - the OP is looking for 30.95.

    My best guess is this:

    =AVERAGE(INDEX(E2:AZZ2,LARGE(COLUMN(E2:AZZ2)*(E2:AZZ2<>""),20)):$AZZ2)

    and it yields 25.25.
    Last edited by AliGW; 05-19-2022 at 02:22 AM.

  19. #19
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Formula to show Average of the last 'N' values in a row.

    I can't find out how to get 30.95 T_T.

    Regards.

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

    Re: Formula to show Average of the last 'N' values in a row.

    Nope - me neither. I wouldn't waste any more of your time until the OP has clarified and given us the information we've been asking for from the very start.

  21. #21
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I've uploaded the sheet again with menem's suggestion. I've put R4 as a formula showing the average of the last 20 cells in Row 2 (counted the cells manually). The value there is 29.083.

    The initial value I mentioned was off, but the suggested formula isn't matching.

  22. #22
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I've also added a file "Sample Database Sheet A" with AliGWs formula. That is generating a #VALUE Error.

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

    Re: Formula to show Average of the last 'N' values in a row.

    The workbook is the same as before - you haven't changed anything.

    How exactly have you calculated 29.083? Exactly which cells do you think should be included?

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

    Re: Formula to show Average of the last 'N' values in a row.

    You have used this:

    =AVERAGE(INDEX(E2:AZZ2,LARGE(@COLUMN(E2:AZZ2)*(@E2:AZZ2<>""),20)):$AZZ2)

    It should be this:

    =AVERAGE(INDEX(E2:AZZ2,LARGE(COLUMN(E2:AZZ2)*(E2:AZZ2<>""),20)):$AZZ2)

  25. #25
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    The last 20 cells are R2:A02. I incorrectly typed N2:AO2. But even with the correct input it's showing 30.1875. I'm updating it with the correct version. Your formula is resulting in an error value. I've uploaded that as Database Sheet A.

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

    Re: Formula to show Average of the last 'N' values in a row.

    This:

    =AVERAGE(N2:AO2)

    includes more than 20 non-blank cells.

    Could you please explain exactly which cells you want to include and why???

  27. #27
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Formula to show Average of the last 'N' values in a row.

    How to get 'N' value ?

    Regards.

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

    Re: Formula to show Average of the last 'N' values in a row.

    Please try this:

    =AVERAGE(INDEX(E2:AZZ2,LARGE(COLUMN(E2:AZZ2)*(E2:AZZ2<>""),20)-4):$AZZ2)
    Attached Files Attached Files

  29. #29
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I uploaded your formula correctly. It's now showing 25.25. But in R4 I've calculated the average of the last 20 rows (I've counted this four or five times to make sure) and it's showing 30.1875. I've calculated it manually with a calculator and the real value is 28.1, so I think Excel is mistakenly considering some added cells for some reason I don't understand.

  30. #30
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    Perfect. This worked. Thank you so much.

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

    Re: Formula to show Average of the last 'N' values in a row.

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you 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 all those who offered help.

  32. #32
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    This formula works perfectly, but it's generating #VALUE errors when I drag it down. Is there a solution for this?

  33. #33
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    I understood what's happened. This formula works perfectly once there are 20 values, but my database will have some entries with a lower sample size than that. Is there a solution that's more elegant than switching the value from 20 to something else.

  34. #34
    Registered User
    Join Date
    05-17-2022
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Formula to show Average of the last 'N' values in a row.

    After checking again, it works perfectly in all cases. Thanks a ton, I'm updating this as solved.

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

    Re: Formula to show Average of the last 'N' values in a row.

    Remove any @ signs that appear when you open my file - that's an issue between versions of Excel.

    Glad it's workking.

+ 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. Replies: 1
    Last Post: 11-29-2019, 04:09 AM
  2. Want Pivot table's average to show average by number of month.
    By jp16 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 07-16-2019, 06:07 AM
  3. [SOLVED] Formula to show the lowest value allowed to maintain an average
    By lukela85 in forum Excel General
    Replies: 4
    Last Post: 11-03-2017, 02:48 PM
  4. Replies: 13
    Last Post: 10-08-2014, 08:35 AM
  5. If (average A1:A10 - 10) = >0, show answer, if not, show blank... Without helper
    By ThomasCarter in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-15-2012, 10:53 AM
  6. formula to show average over specific time frame over multiple sheets
    By bademployee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2010, 08:22 PM
  7. [SOLVED] average cells, show 0 if nothing to average
    By Kycajun in forum Excel General
    Replies: 8
    Last Post: 06-21-2006, 02:40 PM

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