+ Reply to Thread
Results 1 to 11 of 11

Average a range IF within 30 days

  1. #1
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44

    Average a range IF within 30 days

    Hi,
    I have a spreadsheet with dates running down column J, and a number running down column K. I want to average the numbers in column K for all the rows that are less than 30 days old.

    I have a formula for determining if a date is less than a month old:
    =IF(DATEDIF(J2,TODAY(),"d")<31,TRUE,FALSE)

    How can I translate that into averaging a range?

    Thanks,

    Dan

    Edit: I'm using Excel 2003

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    try:

    =AVERAGE(IF(J2:J200>TODAY()-30,K2:K200))

    Adjust ranges to suit and confirm with CTRL+SHIFT+ENTER not just ENTER.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    Thanks. It looks like it should work, but it returns 0 no matter the numbers in the range. Can't figure out why that would be.

    Also, does an IF function not have to have a value if false? Because, this one doesn't.

    Dan

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    It works for me...

    Are you sure the dates are actual dates and not text...

    and that the corresponding numbers are not text...

    With these Array formulas using IF, you don't need the what-if-false, since it only evaluates the Trues, you could put a "" in the false part if you want...

    Maybe you can post an example sheet if you are still having issues?

  5. #5
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    The spreadsheet is attached. The range I want to average is K6 and down for dates J6 and down.

    The dates are formatted as dates; the numer cells are a formula and they work in a simple AVERAGE formula (cell H3). I have placed your formula in N31 to try out (the successful formula will go in H4).
    Attached Files Attached Files

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    You have to confirm the formula with CTRL+SHIFT+ENTER keys...

    Go to N32 and hit F2 to get the cursor in the formula. Hold the CTRL and SHIFT keys down and hit ENTER.

    Also, column K is pretty much empty.. enter some values and you should see the results in N32.

  7. #7
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    Thanks, that made it work. I didn't know about ctrl+shift+enter, what is the purpose of that?

    It might have been working before but I had the cell formatted for no decimals. I put it in H4, formatted for one decimal and it reads 0.5. As data accumulate, the average will become meaningful. There are no data for most days because they don't have a starting datestamp in column C, but the ones below do.

    One more question. It seems it doesn't average for cells that read 0. Is there a way to average 0's but not blanks? The 0's are actually date differences between dates entered at the same day, different times, so I thought the calculated value would be some decimal below 1.

    Thanks for all your help,

    Dan

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See here for explanation of Array (CSE) Formulas: http://www.cpearson.com/excel/ArrayFormulas.aspx

    Try:

    =AVERAGE(IF(J2:J200>TODAY()-30,IF(K2:K200<>"",K2:K200)))

    again confirmed with CSE keys

  9. #9
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    Wait a second, that was wrong. It looks like it's averaging 0's AND blanks. I want it to not include blanks.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See previous post.

  11. #11
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    That page is really interesting, thanks for the link.

+ 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. Average Days between a range of dates?
    By cp_ in forum Excel General
    Replies: 7
    Last Post: 02-08-2008, 08:56 PM
  2. trying to calculate regular days in date range excluding holidays
    By DKY in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2008, 09:12 PM
  3. Fixed Range last 4 weeks moving average
    By matt4003 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-04-2007, 03:26 PM
  4. Average days per month
    By doowop5000 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-27-2007, 10:43 AM
  5. Replies: 16
    Last Post: 03-27-2007, 02:14 AM

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