+ Reply to Thread
Results 1 to 4 of 4

variable moving average periods

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    variable moving average periods

    At some point in the past, I received help here on a formula where I could vary the moving average period on a long row of data.

    The data begins on row 8 and ends somewhere below row 2500.

    I thought that the formula was this (for cell H18):

    Please Login or Register  to view this content.
    Where H3 was the moving average period, column G was the data I'm averaging.

    I'm checking this formula with manual average (for example if H3=2, then my test formula is
    Please Login or Register  to view this content.
    But it is not working. I've tried adjusting the $H$3-1 by various amounts, but I still can't get the right answer. I'm sure the answer is obvious, but that's something I don't always see!

    Thanks
    Last edited by jrtaylor; 08-07-2017 at 03:38 PM.

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: variable moving average periods

    You have to do the math with the ROW function.
    ROW() returns the row number that the function is entered in.
    So if you put that formula in H18, then ROW() = 18
    Your formula changes from
    =(AVERAGEIF(INDEX(G$8:G$2500,ROW()-$H$3-1):INDEX(G$8:G$2500,ROW()),"<>0")
    to
    =(AVERAGEIF(INDEX(G$8:G$2500,18-$H$3-1):INDEX(G$8:G$2500,18),"<>0")

    H3 is 2 you said
    =(AVERAGEIF(INDEX(G$8:G$2500,18-$H$3-1):INDEX(G$8:G$2500,18),"<>0")
    changes to
    =(AVERAGEIF(INDEX(G$8:G$2500,18-2-1):INDEX(G$8:G$2500,18),"<>0")
    becomes
    =(AVERAGEIF(INDEX(G$8:G$2500,15):INDEX(G$8:G$2500,18),"<>0")

    Now, that 15 is NOT a row number.
    It's an INDEX number, relative to the range G8:G2500
    15 means the 15th cell in G8:G2500
    That is G22

    =(AVERAGEIF(G22:INDEX(G$8:G$2500,18),"<>0")

    The 18th cell in G8:G2500 is G25
    =(AVERAGEIF(G22:G25,"<>0")


    So your formula, in H18 while H3 = 2 is averaging G22:G25

  3. #3
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: variable moving average periods

    Hi Jonmo, thanks. I was playing around with the wrong number. I appreciate your help!

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: variable moving average periods

    You're welcome.

+ 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. [SOLVED] variable moving average periods
    By jrtaylor in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-01-2016, 11:24 AM
  2. Replies: 1
    Last Post: 10-20-2014, 03:20 PM
  3. [SOLVED] Calculate Average Price For Various Periods
    By Flanders in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-14-2014, 02:24 PM
  4. Moving average across variable range
    By SRKfc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-03-2013, 06:11 PM
  5. [SOLVED] How to calculate a rolling average over X periods
    By Johnex777 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-03-2013, 10:37 AM
  6. Moving average of a moving average in the same cell
    By philroberts1983 in forum Excel General
    Replies: 8
    Last Post: 09-16-2008, 07:36 AM
  7. average rolling periods
    By RobPatrick in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2007, 05:26 AM

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