+ Reply to Thread
Results 1 to 5 of 5

Thread: How do I use an array formula linking to today's date?

  1. #1
    Registered User
    Join Date
    11-06-2011
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2003
    Posts
    2

    How do I use an array formula linking to today's date?

    Hi
    I'm trying to calculate moving averages linked to today's date using vlookup. Example data is below. I can get the 7 day Moving Average using the following cumbersome vlookup formula (=AVERAGE(VLOOKUP(F3,D29:E36,2,FALSE), VLOOKUP(F3-1,D29:E36,2,FALSE), VLOOKUP(F3-2,D29:E36,2,FALSE),VLOOKUP(F3-3,D29:E36,2,FALSE), VLOOKUP(F3-4,D29:E36,2,FALSE), VLOOKUP(F3-5,D29:E36,2,FALSE),VLOOKUP(F3-6,D29:E36,2,FALSE))

    Not much good for the 30 day moving average formula though. Can I use an array formula to do this better?

    Thanks for any help


    Today 8/10/2011

    Sales 7 Day Moving Average 30 Day Moving Average
    8/09/2011 20 27.14285714
    9/09/2011 0
    10/09/2011 10
    11/09/2011 60
    12/09/2011 60
    13/09/2011 10
    14/09/2011 0
    15/09/2011 0
    16/09/2011 10
    17/09/2011 60
    18/09/2011 60
    19/09/2011 20
    20/09/2011 10
    21/09/2011 60
    22/09/2011 60
    23/09/2011 10
    24/09/2011 0
    25/09/2011 0
    26/09/2011 10
    27/09/2011 60
    28/09/2011 60
    29/09/2011 50
    30/09/2011 30
    1/10/2011 20
    2/10/2011 50
    3/10/2011 0
    4/10/2011 10
    5/10/2011 60
    6/10/2011 60
    7/10/2011 10
    8/10/2011 0

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,220

    Re: How do I use an array formula linking to today's date?

    SUMPRODUCT() should be able to do it:

    =SUMPRODUCT(--($A$1:$A$1000<=TODAY()), --($A$1:$A$1000>TODAY()-30), $B$1:$B$1000) / SUMPRODUCT(--($A$1:$A$1000<=TODAY()), --($A$1:$A$1000>TODAY()-30))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How do I use an array formula linking to today's date?

    FWIW, I would advise against using volatiles like TODAY in conjunction with SUMPRODUCT.

    If an Array / SUMPRODUCT is required I would suggest entering date of interest as a static value - use VBA to do this via Workbook Open even if preferred

    If as implied by your data set it is:

    1 - always sorted by date
    2 - inclusive of every date
    3 - one entry per date

    or combinations thereof you should find you can use some fairly standard formulae to calculate your averages

    Are you able to post up a more complete data set via sample file ?

    Also, to confirm, XL2003 ?

  4. #4
    Registered User
    Join Date
    11-06-2011
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: How do I use an array formula linking to today's date?

    thanks mate that works. Can't say I understand it though! Is the "--" symbol another way of representing "if"

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: How do I use an array formula linking to today's date?

    -- is double unary and in this instance is used to coerce boolean (True/False) to integer equivalent (native XL 1/0 respectively)

    For a good overview of SUMPRODUCT inclusive of coercion see SUMPRODUCT link in my sig. (Bob Phillips' white paper)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0