+ Reply to Thread
Results 1 to 8 of 8

moving average with differing bin sizes

  1. #1
    Registered User
    Join Date
    11-02-2011
    Location
    oxford
    MS-Off Ver
    Excel 2007
    Posts
    6

    moving average with differing bin sizes

    Hello forum!

    I am trying to calculate a moving average, but im having issues because its not always the average of the same number of values; this changes. So.. I want the average of 1 column (e.g. column A below) to be calculated based on whether they are in the categories 0-50, 25-75 etc (listed in columns D and E below) from another column (e.g. column B below) and ending up in a nice neat column (e.g. G below). To add an extra layer of complexity there are a handful of missing data points (denotes as '.' below), so simply sumif(...)/(countif(...) wont work because it will 'sumif' ignoring the blanks in col A, and 'countif' if there is data present in col B, e.g. in the category 50-100 below the average is 20/3 not 20/5. (or maybe this latter step can be fixed?). This little dataset is also attached as a .xlsx

    (Also there are several thousand datapoints so I dont want to manually make a couple of hundred 'average' calculations!)

    Any help would be gratefully appreciated!!!!

    A B D E G
    2 2 0 50 4.625
    3 11 25 75 6
    6 12 50 100 6.666
    7 12
    5 14
    4 23
    3 34
    7 45
    6 51
    . 55
    . 55
    8 70
    6 86
    Attached Files Attached Files
    Last edited by mchapman47; 04-03-2013 at 03:57 PM. Reason: solved!

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: moving average with differing bin sizes

    Are blank rows included in determining where your averages start and stop.
    For example, if you have data in A2:A101, with a scattering of blank cells, Does 50-100 start in A51 or it depends on how many blanks and where they are?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    11-02-2011
    Location
    oxford
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: moving average with differing bin sizes

    Hi, Im afraid not, the blank cells are missing data interspersed essentially randomly throughout the column, theyre not before or after any particular values. Thanks!

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: moving average with differing bin sizes

    ExcelHelp.xlsx

    Not the most elegant but it works and it's fast
    Elegant Simplicity............. Not Always

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: moving average with differing bin sizes

    Didn't look at Andy's yet but this works

    =SUMPRODUCT(--($B$2:$B$14>=D2),--($B$2:$B$14<=E2),$A$2:$A$14)/SUMPRODUCT(--($B$2:$B$14>=D2),--($B$2:$B$14<=E2),--($A$2:$A$14<>""))

  6. #6
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: moving average with differing bin sizes

    Note to self - get a handle on Sumproduct

  7. #7
    Registered User
    Join Date
    11-02-2011
    Location
    oxford
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: moving average with differing bin sizes

    champion! thanks a lot guys! =sumproduct was driving my up the wall earlier so I gave up on it, but Im glad I was at least in the right area!
    thanks again!

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

    Re: moving average with differing bin sizes

    Quote Originally Posted by AndyLitch View Post
    Note to self - get a handle on Sumproduct
    Here's a good place to start:

    http://xldynamic.com/source/xld.SUMPRODUCT.html
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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