+ Reply to Thread
Results 1 to 5 of 5

Thread: Calculating the average over the last 5 values.

  1. #1
    Registered User
    Join Date
    11-11-2011
    Location
    Derby, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Calculating the average over the last 5 values.

    I am looking for a formula to calculate the average for each row of numbers but to only pick the last 5 values (but to ignor 0).

    So the averages of the below rows
    A 22 22 26 24 0 0 21 59 74 68
    B 100 98 100 0 90 100 94 95 91 49
    C 56 0 0 0 0 0 52 95 41 28
    D 47 80 0 50 0 47 0 95 0 97

    As time goes on there will be more data added these (in the spreadsheet 0's will be blank) so the formula will need to average the last 5 data points from the right of the row.

  2. #2
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Calculating the average over the last 5 values.

    Welcome to the forum.

    Taking row A as an example, I'd just like to clarify a point about ignoring the zeros.

    Which of these do you want to be the average?

    (24 + 21 + 59 + 74 + 68) / 5

    or

    (21 + 59 + 74 + 68) / 4



    Assuming you want the first of these variations, this array formula (CTRL+SHIFT+ENTER) should do the trick:
    =AVERAGE(INDEX(3:3,,LARGE(ISNUMBER(3:3)*COLUMN(3:3),5)):IV3)
    Last edited by Colin Legg; 11-11-2011 at 01:55 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  3. #3
    Registered User
    Join Date
    11-01-2011
    Location
    Boca Raton, Florida
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Calculating the average over the last 5 values.

    I tried the formula but am getting a DIV/0 error. Do you need both commas after 3:3? what does IV3 refer to?

    Thanks,

    Sharon

  4. #4
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Calculating the average over the last 5 values.

    Hi,

    Yes, you need both commas
    IV3 refers to the last cell in the column (based on Excel 2003).
    The formula I gave was for row 3; you have to adjust the row references for the other rows.

    You would get a DIV/0 error if the row is empty.

    I have attached example.
    Attached Files Attached Files
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  5. #5
    Registered User
    Join Date
    11-11-2011
    Location
    Derby, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Calculating the average over the last 5 values.

    I tried that and got a circular referance. Can you PM me a spreadsheet so i can copy and paste?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0