+ Reply to Thread
Results 1 to 5 of 5

how to count # rows having overlapping date ranges

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

    how to count # rows having overlapping date ranges

    I've attached a spreadsheet to illustrate the question.

    It shows various trades, including opening and closing times.

    Some trades "overlap" others.

    For any particular row, in column C, I need to count how many other trades are open at the same time.

    It seems like it should be a simple formula but I'm not having success either with COUNTIF or SUMIFS.

    thanks in advance for the help!
    Attached Files Attached Files
    Last edited by jrtaylor; 09-13-2011 at 01:59 PM. Reason: solved

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: how to count # rows having overlapping date ranges

    I've taken a look at your workbook and i'm still not wiser, i cannot fathom out what you are trying to acheive or where you are checking for overlaps...etc
    Not all forums are the same - seek and you shall find

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

    Re: how to count # rows having overlapping date ranges

    I hope this will help:

    1. This is a spreadsheet of currency trades.

    2. Each trade opens at a certain time/date (column J) and closes at a certain time/date (column L). (note the date formats are US, not UK).

    3. The spreadsheet is sorted by column L, in ascending order.

    4. You will notice that some trades last longer than others. As a consequence, there are times when more than one trade is open.

    5. For the example I refer to in the spreadsheet (the trade on row 5) you will see that it opened on 9/30/2009 21:00, and closed on 10/01/2009 at 13:10. Let's call that "date range 5"

    6. The task now is to see if any other trades were open during "date range 5."

    7. If we look at rows 3 and 4 we see that both of them were open at some point during "date range 5." (they opened later than 5, but 5 remained open during part of time that 5 was still open). Thus the date ranges "overlapped."

    8. The formula I need should "count" rows 3,4 and 5, giving a solution of "3."

    It seems to me that the formula would need to be a SUMIFS and include MAX/MIN calcs. But how to write it... is beyond me!
    Thanks much.
    Last edited by jrtaylor; 09-13-2011 at 11:32 AM. Reason: point out american time convention

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: how to count # rows having overlapping date ranges

    I think the formula should be =COUNTIFS($J$2:$J$12,">=" & J2,$L$2:$L$12,"<=" & L2), but it doesn't return quite the same results as your manually calculated results.

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

    Re: how to count # rows having overlapping date ranges

    Andrew, thank you. I think your formula solves the problem. ( My manual calcs are obviously subject to human error (!))

    I wasn't familiar with COUNTIFS. I assume the logic is similar to SUMIFS.

    Thanks again!

+ 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.6.0 RC 1