+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : average last 5 values meeting certain criteria

  1. #1
    Registered User
    Join Date
    05-14-2010
    Location
    Visalia, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    average last 5 values meeting certain criteria

    Hi,
    I am using the following formula
    =AVERAGEIF(D$2:D447, D448, K$2:K447)
    which gives me the average of all the values from k2 to k447 that meet certain criteria. Is there a way to get just the average of the last 5 entries that meet that same criteria rather than all entries.

    Jared
    Last edited by jrbdotcom31; 05-15-2010 at 11:50 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: average last 5 values meeting certain criteria

    Try:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER and not just ENTER.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    05-14-2010
    Location
    Visalia, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: average last 5 values meeting certain criteria

    Quote Originally Posted by NBVC View Post
    Try:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER and not just ENTER.
    Thank you. However, for some reason, it is not giving my the correct value that I have computed manually. Can you explain the Row(D$2)+1 part so that I can understand the code better and try to make it work. Thanks in advance.

    jared

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: average last 5 values meeting certain criteria

    You are correct, the formula should be more like:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER.

    the -ROW(D2)+1 basically resets the array created by ROW(D2:D447) to start from 1.. So Row(D2) is subtracted from each element in ROW(D2:D447) to give an array like {0,1,2,3,....etc} and then 1 is added to each, so that array begins at 1...

    Then, each Row number replaces the TRUE results of the D2:D447=D448 condition.. and the large() finds the kth largest row number and extract the reference at that point.... This is repeated to find the largest (or last time the condition is true) and a range is found.. then within that range, the AVERAGE(IF()) is used to get the average of the elements in K where D is equal to D448.

  5. #5
    Registered User
    Join Date
    05-14-2010
    Location
    Visalia, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: average last 5 values meeting certain criteria

    Quote Originally Posted by NBVC View Post
    You are correct, the formula should be more like:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER.

    the -ROW(D2)+1 basically resets the array created by ROW(D2:D447) to start from 1.. So Row(D2) is subtracted from each element in ROW(D2:D447) to give an array like {0,1,2,3,....etc} and then 1 is added to each, so that array begins at 1...

    Then, each Row number replaces the TRUE results of the D2:D447=D448 condition.. and the large() finds the kth largest row number and extract the reference at that point.... This is repeated to find the largest (or last time the condition is true) and a range is found.. then within that range, the AVERAGE(IF()) is used to get the average of the elements in K where D is equal to D448.
    Thank You so much! It worked!!! I tried several ideas, but couldn't find the right approach. By the looks of it, I probably never would have. Thanks again for the formula and the explanation so that I can learn more as well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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