+ Reply to Thread
Results 1 to 14 of 14

Average of last 5 values but to exclude any blank cells.

  1. #1
    Registered User
    Join Date
    07-03-2014
    Location
    Newcastle upon Tyne
    MS-Off Ver
    2007
    Posts
    3

    Average of last 5 values but to exclude any blank cells.

    Hi
    I wonder if anyone can assist.
    I have a scenario where I have a rolling list of sales figures which get added to each week that passes.

    I need a formula that will calculate the last 5 weeks of sales and generate an average - which I think I have an idea how to do.
    The sticking point is that so as not to skew the averages, when there has been an exceptionally busy or quiet day for a reason we know about I exclude the sales from that week.
    This then interferes with the averages as it either takes it as a zero and lowers it or seems to stop formulas from working.

    So to summarise:

    Average of last 5 weeks sales
    Excluding any blanks
    Dynamic enough to always pick up the last 5 values in the list (i.e. the last 5 weeks)

    Any assistance greatly appreciated.
    Tim

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Average of last 5 values but to exclude any blank cells.

    =sumif(A:A,">=" & today()-35)/countif(A:A,">=" & today()-35)

    i havent tested as not in excel at the minute. SOmething like this, this doesnt exclude 0's, but you can use the IFS extensions of SUM and COUNT to exclude the 0's also.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Average of last 5 values but to exclude any blank cells.

    Where is the data located? In a row? A column?

    Will there always be at least 5 numbers to average? If not, what should happen?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    07-03-2014
    Location
    Newcastle upon Tyne
    MS-Off Ver
    2007
    Posts
    3

    Re: Average of last 5 values but to exclude any blank cells.

    The data will be in columns with the last 5 entries (weeks) always needing to be averaged.
    The scenario is that the column will increase weekly as the next weeks sales for that particular day are added but the figure required by the formula is the average of the last 5 entries in the column (but not including any blanks that may be present within that last 5 entries)

    Does that make sense?

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Average of last 5 values but to exclude any blank cells.

    Try this...

    Data Range
    A
    B
    C
    1
    Sales
    ------
    AVG last 5
    2
    98
    63.4
    3
    86
    4
    5
    53
    6
    80
    7
    58
    8
    89
    9
    10
    59
    11
    28
    12
    13
    14
    81
    15
    60


    This array formula** entered in C2:

    =IFERROR(AVERAGE(IF(ROW(A2:A20)>=LARGE(IF(A2:A20<>"",ROW(A2:A20)),MIN(COUNT(A2:A20),5)),IF(A2:A20<>"",A2:A20))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    It will average the last (bottom-most) 5 entries. If there aren't 5 entries it will average what's available.
    Last edited by Tony Valko; 07-03-2014 at 10:20 AM.

  6. #6
    Registered User
    Join Date
    07-03-2014
    Location
    Newcastle upon Tyne
    MS-Off Ver
    2007
    Posts
    3

    Re: Average of last 5 values but to exclude any blank cells.

    Tony that's amazing and works perfectly - thank you so much.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Average of last 5 values but to exclude any blank cells.

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

  8. #8
    Registered User
    Join Date
    05-14-2017
    Location
    Detroit, mi
    MS-Off Ver
    2007
    Posts
    2

    Re: Average of last 5 values but to exclude any blank cells.

    What would this array formula look like if I wanted to average the FIRST 5 VALUES instead of the LAST FIVE ???

  9. #9
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,465

    Re: Average of last 5 values but to exclude any blank cells.

    Quote Originally Posted by RTJones View Post
    What would this array formula look like if I wanted to average the FIRST 5 VALUES instead of the LAST FIVE ???
    Not yet tested, but try to replace ">=LARGE" with "<=SMALL"
    Quang PT

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Average of last 5 values but to exclude any blank cells.

    RTJones welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  11. #11
    Registered User
    Join Date
    05-14-2017
    Location
    Detroit, mi
    MS-Off Ver
    2007
    Posts
    2

    Re: Average of last 5 values but to exclude any blank cells.

    Ford: SORRY for not knowing better. As you can see, I'm very new to this. Also, I couldn't figure out how to start my own thread (newbie!!!!).

    Note....I replaced ">=LARGE" with "<=SMALL" as suggested and it worked perfectly!!!! THANK YOU

  12. #12
    Registered User
    Join Date
    09-01-2018
    Location
    Pittsburgh
    MS-Off Ver
    Using MAC
    Posts
    1

    Re: Average of last 5 values but to exclude any blank cells.

    Tony, Noticed you were a Pens fan, ditto here. I just wanted to thank you for you post. I have been working on this since 11am today and came across your post. This is exactly what I needed. Thank you so much! Go Pens!!!!!

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Average of last 5 values but to exclude any blank cells.

    TPL57, thanks for the feedback, always appreciated

  14. #14
    Registered User
    Join Date
    01-12-2019
    Location
    Florida
    MS-Off Ver
    Office 2013
    Posts
    2

    Re: Average of last 5 values but to exclude any blank cells.

    Quote Originally Posted by Tony Valko View Post
    Where is the data located? In a row? A column?

    Will there always be at least 5 numbers to average? If not, what should happen?
    I wanted to know what can be done if there are not always going to be 5 numbers to average? There will always be at least 1 number but could be anywhere between 1 and 5.
    Would like excel to return the average even if its just 1 number
    I switched it to Columns for use on a table Capture.PNG
    Last edited by Beefyman61; 01-12-2019 at 03:17 PM.

+ 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: 07-19-2012, 05:09 PM
  2. AVERAGE calculation to exclude blank cells
    By andrewc in forum Excel General
    Replies: 8
    Last Post: 09-04-2009, 03:30 AM
  3. How to average cells but exclude 0 values?
    By Billznik in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-27-2008, 06:26 AM
  4. Average needed, but want to exclude some values
    By hibiscus27 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2007, 10:49 AM
  5. Replies: 1
    Last Post: 07-20-2005, 06:05 PM

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.6.0 RC 1