+ Reply to Thread
Results 1 to 6 of 6

Count # of months in date range

  1. #1
    Forum Contributor
    Join Date
    06-25-2007
    Posts
    166

    Count # of months in date range

    Hi,

    I have a list of hundreds of dates in a single column. I'm trying to figure out how many months are spanned by the list. The earliest and latest dates are not explicitly singled out or located anywhere specific - they may be placed anywhere in the list.

    Until now, I've been using this:

    =MONTH(MAX(DateRange))-MONTH(MIN(DateRange))+1

    ...where "DateRange" is the column of data containing the hundreds of dates. This worked well until recently where there are now dates across multiple years. So, for example, if the earliest date is 12/27/07 and the latest date is 3/31/08, that should be 4 months (Dec, Jan, Feb, Mar), instead of 10 as the formula would churn out (12-3+1).

    How can I manipulate the formula to get 4? Thanks in advance-

    JChandler

  2. #2
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    Please Login or Register  to view this content.

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

    =DATEDIF(MIN(DateRange),MAX(DateRange),"m")+1
    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.

  4. #4
    Forum Contributor
    Join Date
    06-25-2007
    Posts
    166
    Thank you very much, that worked well.

    I've since encountered another problem.

    If the span of months was from Nov '07 to Jun '08, but there are no Feb dates included anywhere in the long list of dates, what function would count 7 instead of 8?

    Thanks again in advance.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Count # of months in date range

    With
    A1:A20 containing various dates (and possibly some blanks)

    This ARRAY FORMULA (committed with CTRL+SHIFT+ENTER,
    instead of just ENTER) returns the count of unique months:
    Please Login or Register  to view this content.
    EDITED to include this regular (non-array)
    AND RE-EDITED to prevent it from returning: 1 when no values are present:
    Please Login or Register  to view this content.
    Is that something you can work with?
    Last edited by Ron Coderre; 07-17-2008 at 09:28 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    There's probably a better way.. but here's one way...

    Say your list of dates covers A1:A6, create a list of all the months in a year somewhere in the sheet, so list "January" to "December" in say F2:F13.

    Now use this formula:

    Please Login or Register  to view this content.
    which must be confirmed with CTRL+SHIFT+ENTER not just ENTER... you will see { } brackets appear around the formula.

    If you make adjustments to the formula, you must reconfirm with the CSE keys.

+ 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