+ Reply to Thread
Results 1 to 5 of 5

Conditionally extending range of rolling average -- ??

  1. #1
    Registered User
    Join Date
    01-28-2011
    Location
    San Francisco area, California, US
    MS-Off Ver
    Excel 2003, 2007, 2010/2011
    Posts
    11

    Conditionally extending range of rolling average -- ??

    Hi folks,

    I work with sets of data in which there is data provided for each hour over periods of several years.

    I often have to calculate "rolling averages" in which the result displays the average of values over the prior 30 days (the prior 720 hourly entries). That part is easy enough -- on the 721st record (on row 722, since I have a header row), and those further down, I sum the entries of the previous 720 rows from the desired column.

    Here's the hitch:

    I need to find a way to extend the range under certain conditions.

    Specifically, whenever there are no entries during a whole calendar day ((all 24 hourly entries for that particular date are blank), then I need to skip that date and not count it as one of the days in the "30-day" average, and extend the range of rows averaged by an extra day (an extra 24 rows).

    This can happen several times in a month. For example, if there are three days with no data entries at all, then I really need to average over the previous 33 days (792 hours / 792 rows), to make up for the 3 days with no data. If there are 7 days with no data, then I really need to average existing entries over 37 days, and so forth.

    Is there a good way to set up a calculation to do this?

    Desperately needed. Any help much appreciated.

    Thanks.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Conditionally extending range of rolling average -- ??

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  3. #3
    Registered User
    Join Date
    01-28-2011
    Location
    San Francisco area, California, US
    MS-Off Ver
    Excel 2003, 2007, 2010/2011
    Posts
    11

    Re: Conditionally extending range of rolling average -- ??

    Thanks.

    Here is a super-pared-down version of a sample data set:
    http://www.sendspace.com/file/d5pvz0 (~18kb)

    In this file, I have assumed that a day has only three hours in it (not 24)
    and I've set up a 5-day rolling average (not 30-day).

    On the single worksheet, I've included:
    1.
    1. An example of how I am calculating rolling averages now
    2. And two ways cells could be selected to get the new desired result ("Method B" would be the most useful for our purposes):
      A. Extending the 'look-back' range by a number of cells equal to the number of cells in the range that occur on entirely blank days
      B. Entirely omitting from the look-back calculation any cells that occur on entirely blank days

    In order to set up this example, I had to manually enter the rolling average calculations in most of the cells for each of the "After" cases. Obviously, that is not practicable when I am dealing with tens or hundreds of thousands of rows.

    So, the goal is that the "rolling average" column should have a single, uniform calculation.

    If it is not possible to do this with a calculation, is there some other way?

    Thank you.
    Last edited by burro; 04-29-2011 at 12:49 PM.

  4. #4
    Registered User
    Join Date
    01-28-2011
    Location
    San Francisco area, California, US
    MS-Off Ver
    Excel 2003, 2007, 2010/2011
    Posts
    11

    Re: Conditionally extending range of rolling average -- ?? Simpler

    If that problem is too hard, there is a much simpler challenge that would help:

    Forgetting about hours, for this moment, just consider daily data.

    I need to be able to average the previous 5 non-blank data entries.

    So if there is one or more blanks in the previous rows the cell range selected for the average function has to be extended. (See attached file.)

    Is there a way to do this?

    Is there a way using dynamic range functions?

    Anything, anything that could help would be most appreciated!
    Attached Files Attached Files

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Conditionally extending range of rolling average -- ??

    ok with a helper column
    see cols j:k
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ 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