+ Reply to Thread
Results 1 to 16 of 16

Calculate a 30-day moving average based on the last x number of entries and date

  1. #1
    Registered User
    Join Date
    06-23-2006
    Posts
    13

    Calculate a 30-day moving average based on the last x number of entries and date

    Hello, I have a worksheet that has all weekday dates in column 1 and values in column 2. I want to create a 30-day moving average based on the last (non-zero) value in the column 2. Since every month has a different amount of days, I want it to search the date that has the last value (since I don't get a chance to update it daily) and go back thirsty days from that date and give an average of all the column 2 values skipping and values that are null or zero.

    Any ideas?

    Thanks,

    Gimi

  2. #2
    salut
    Guest

    RE: Calculate a 30-day moving average based on the last x number of en

    Assume your last row is 1000
    Then your average of the value in the second column for the last 30 days
    would be:

    =Average(Offset(B1000,0,0,-30,1))


    "gimiv" wrote:

    >
    > Hello, I have a worksheet that has all weekday dates in column 1 and
    > values in column 2. I want to create a 30-day moving average based on
    > the last (non-zero) value in the column 2. Since every month has a
    > different amount of days, I want it to search the date that has the
    > last value (since I don't get a chance to update it daily) and go back
    > thirsty days from that date and give an average of all the column 2
    > values skipping and values that are null or zero.
    >
    > Any ideas?
    >
    > Thanks,
    >
    > Gimi
    >
    >
    > --
    > gimiv
    > ------------------------------------------------------------------------
    > gimiv's Profile: http://www.excelforum.com/member.php...o&userid=35726
    > View this thread: http://www.excelforum.com/showthread...hreadid=558670
    >
    >


  3. #3

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    gimiv wrote:
    > Hello, I have a worksheet that has all weekday dates in column 1 and
    > values in column 2. I want to create a 30-day moving average based on
    > the last (non-zero) value in the column 2. Since every month has a
    > different amount of days, I want it to search the date that has the
    > last value (since I don't get a chance to update it daily) and go back
    > thirsty days from that date and give an average of all the column 2
    > values skipping and values that are null or zero.


    The solution might be a lot simpler than you might think. But your
    description leaves me with several questions, so I am not sure. Does
    the following paradigm work for you?

    Assume your data starts in B2. The first 30 days of data are in
    B2:B31, some cells of which might be zero presumably because you "did
    not get a chance to update it daily". It appears that you want the
    following average, entered into C31 perhaps:

    =sumif(B2:B31,"<>0") / countif(B2:B31,"<>0")

    If you copy that down the column, the range will automatically be a
    moving 30-day period; for example, B3:B32, B4:B33, etc. Thus, it
    creates a trailing simple moving average, ignoring cells with zero.


  4. #4
    Domenic
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    Assuming that Column B contains the data, try...

    =AVERAGE(IF(ROW(B2:B1000)>=LARGE(IF(B2:B1000,ROW(B2:B1000)),30),IF(B2:B10
    00,B2:B1000)))

    ....confirmed with CONTROL+SHIFT+ENTER, not just ENTER.

    Hope this helps!

    In article <[email protected]>,
    gimiv <[email protected]> wrote:

    > Hello, I have a worksheet that has all weekday dates in column 1 and
    > values in column 2. I want to create a 30-day moving average based on
    > the last (non-zero) value in the column 2. Since every month has a
    > different amount of days, I want it to search the date that has the
    > last value (since I don't get a chance to update it daily) and go back
    > thirsty days from that date and give an average of all the column 2
    > values skipping and values that are null or zero.
    >
    > Any ideas?
    >
    > Thanks,
    >
    > Gimi


  5. #5

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    [email protected] wrote:
    > gimiv wrote:
    > > values skipping and values that are null or zero.

    > [....]
    > =sumif(B2:B31,"<>0") / countif(B2:B31,"<>0")


    I just realized that you said skipping cells that are zero __or_null__.
    In that case, you might want:

    =sumif(B2:B31,"<>0") / (counta(B2:B31) - countif(B2:B31,"=0"))


  6. #6
    Registered User
    Join Date
    06-23-2006
    Posts
    13

    THanks for all the replies

    However, so far none of these have worked. More specifically, My moving average formula will reside on another worksheet and should change every time I add a new row. I want to avoid a static calculation that I have to re-reference every time.

    Thanks again,

    Gimiv

  7. #7
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    Quote Originally Posted by gimiv
    However, so far none of these have worked. More specifically, My moving average formula will reside on another worksheet and should change every time I add a new row. I want to avoid a static calculation that I have to re-reference every time.

    Thanks again,

    Gimiv
    On the sheet with the data (or elsewhere, depends on what you want), put the following:

    D1: Last Date
    D2: =DMAX(A:B,"Date",E1:E2)

    E1: Value
    E2: >0

    F1: Date
    F2: ="<="&D2

    G1: Date
    G2: =">"&D2-30

    H1: 30-Day Average
    H2: =DAVERAGE(A:B,"Value",E1:G2)

    Then, on the sheet you want to know the 30-Day Average, just reference this sheet's H2 cell.

    Scott

  8. #8
    Domenic
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    In article <[email protected]>,
    gimiv <[email protected]> wrote:

    > However, so far none of these have worked.


    1) Did you confirm the formula with CONTROL+SHIFT+ENTER, not just ENTER.

    2) Are you receiving an error message or an incorrect result? If the
    former, what type of error value are you getting?

    > More specifically, My moving
    > average formula will reside on another worksheet and should change
    > every time I add a new row. I want to avoid a static calculation that I
    > have to re-reference every time.


    For this you can use a dynamic named range. Do you need help with this?

  9. #9
    Registered User
    Join Date
    06-23-2006
    Posts
    13
    For this you can use a dynamic named range. Do you need help with this?[/QUOTE]

    Inserting it into an OFFSET in your equation? yes. = ) thanks again for your help guys.

  10. #10
    Domenic
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    Assuming that Sheet1, Column B, starting at B2, contains the data, try
    the following...

    1) Define the following dynamic named range:

    Insert > Name > Define

    Name: Values

    Refers to:

    =Sheet1!$B$2:INDEX(Sheet1!$B$2:$B$65536,MATCH(9.99999999999999E+307,Sheet
    1!$B$2:$B$65536))

    Click Ok

    Change the references accordingly.

    2) Then try the following formula, which needs to be confirmed with
    CONTROL+SHIFT+ENTER...

    =AVERAGE(IF(ROW(Values)>=LARGE(IF(Values,ROW(Values)),30),IF(Values,Value
    s)))

    Hope this helps!

    In article <[email protected]>,
    gimiv <[email protected]> wrote:

    > For this you can use a dynamic named range. Do you need help with this?
    >
    > Inserting it into an OFFSET in your equation? yes. = ) thanks again for
    > your help guys.


  11. #11
    Biff
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    Note to the OP:

    If you have less than 30 values <> 0 you'll get a #NUM! error.

    Biff

    "Domenic" <[email protected]> wrote in message
    news:[email protected]...
    > Assuming that Sheet1, Column B, starting at B2, contains the data, try
    > the following...
    >
    > 1) Define the following dynamic named range:
    >
    > Insert > Name > Define
    >
    > Name: Values
    >
    > Refers to:
    >
    > =Sheet1!$B$2:INDEX(Sheet1!$B$2:$B$65536,MATCH(9.99999999999999E+307,Sheet
    > 1!$B$2:$B$65536))
    >
    > Click Ok
    >
    > Change the references accordingly.
    >
    > 2) Then try the following formula, which needs to be confirmed with
    > CONTROL+SHIFT+ENTER...
    >
    > =AVERAGE(IF(ROW(Values)>=LARGE(IF(Values,ROW(Values)),30),IF(Values,Value
    > s)))
    >
    > Hope this helps!
    >
    > In article <[email protected]>,
    > gimiv <[email protected]> wrote:
    >
    >> For this you can use a dynamic named range. Do you need help with this?
    >>
    >> Inserting it into an OFFSET in your equation? yes. = ) thanks again for
    >> your help guys.




  12. #12
    Domenic
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    Thanks Biff! Where do I send my cheque... <VBG>

    In article <[email protected]>,
    "Biff" <[email protected]> wrote:

    > Note to the OP:
    >
    > If you have less than 30 values <> 0 you'll get a #NUM! error.
    >
    > Biff


  13. #13
    Registered User
    Join Date
    06-23-2006
    Posts
    13
    Quote Originally Posted by Biff
    Note to the OP:

    If you have less than 30 values <> 0 you'll get a #NUM! error.

    Biff

    "Domenic" <[email protected]> wrote in message
    news:[email protected]...
    > Assuming that Sheet1, Column B, starting at B2, contains the data, try
    > the following...
    >
    > 1) Define the following dynamic named range:
    >
    > Insert > Name > Define
    >
    > Name: Values
    >
    > Refers to:
    >
    > =Sheet1!$B$2:INDEX(Sheet1!$B$2:$B$65536,MATCH(9.99999999999999E+307,Sheet
    > 1!$B$2:$B$65536))
    >
    > Click Ok
    >
    > Change the references accordingly.
    >
    > 2) Then try the following formula, which needs to be confirmed with
    > CONTROL+SHIFT+ENTER...
    >
    > =AVERAGE(IF(ROW(Values)>=LARGE(IF(Values,ROW(Values)),30),IF(Values,Value
    > s)))
    >
    > Hope this helps!
    >
    > In article <[email protected]>,
    > gimiv <[email protected]> wrote:
    >
    >> For this you can use a dynamic named range. Do you need help with this?
    >>
    >> Inserting it into an OFFSET in your equation? yes. = ) thanks again for
    >> your help guys.
    Wow, this worked perfectly. Hate to be a pain, but can you explain how you went about the logic to achieve this statement or does that just come with years and years of experience. I mean, to be able to identify the problem and match it to the right complex formula?

  14. #14
    Domenic
    Guest

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    In article <[email protected]>,
    gimiv <[email protected]> wrote:

    > Wow, this worked perfectly. Hate to be a pain, but can you explain how
    > you went about the logic to achieve this statement or does that just
    > come with years and years of experience. I mean, to be able to identify
    > the problem and match it to the right complex formula?


    Basically, I watch and learn from others who are more experienced. It's
    amazing what one can learn by frequenting these newsgroups, forums,
    etc...

  15. #15
    Registered User
    Join Date
    08-04-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    I have a similar dilemma. I have a worksheet that has dates in one column (Column D) and corresponding sales in another (Column I). On a separate worksheet I have a chart with a data and want one column to automatically calculate a 30-day moving average based on the data from the other worksheet and today's date. There is not one row per day of the month. I have attached the worksheets.
    Attached Files Attached Files
    Last edited by jbroulette; 05-26-2016 at 11:34 PM.

  16. #16
    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,926

    Re: Calculate a 30-day moving average based on the last x number of entries and date

    jbroulette 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

+ 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