Closed Thread
Results 1 to 27 of 27

Figure out occurence of overlapping date & time

  1. #1
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Figure out occurence of overlapping date & time

    Hello all. I hope I explain this well enough.

    I have a spreadsheet of all of my company's long distance calls for last month - 30k rows. It includes the start time of the call and the duration. From that I can calculate the end time of the call.
    My phone system can handle 24 concurrent calls. I'm trying to see how many times throughout the month did we have 24 or more calls going on at once.

    Assume Start_Time is Column_A and End_Time is Column_B
    Currently I can test if one call is going on at the same time a second call is by this formula
    Please Login or Register  to view this content.
    Basically, testing to see if Call 1 starts after Call 2 starts and before Call 2 ends OR if Call 1 ends after Call 2 starts and before Call 2 ends.
    What I don't know how to do is to test this against the other 30k rows and do a COUNTIF on all the TRUE values.

    I hope this wasn't too convoluted. I apologize in advance if it is.
    Thanks for your help.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    OK,

    this may seem harder than it is.

    Assume Start_Time is Column_A and End_Time is Column_B
    In another column, for example column C, enter this formula in row 2 (I assume row 1 has titles) and copy down your 30,000 lines:

    =SUMPRODUCT(--($A$2:$A$30000<A2),--($B$2:$B$30000>A2))+1

    This formula in plain English says: I am the call that is recorded in cell A2. Show me how many other calls in the list have a start time smaller than me AND an end time greater than my start time. Because the SUMPRODUCT formula only counts the OTHER calls, add a 1 for the call recorded in this row.

    The result is a number. For each call you can see how many calls occurred in the same time window as this call.

    Now, somewhere else on your spreadsheet, you could count how often you have 24 concurrent calls with a formula like

    =COUNTIF(C2:C30000,24)

    Does that work for you?

  3. #3
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Wow. I think that works. I will have to go back and verify but it looks like it's working. I don't think I have the formula right to check overlap since there is 4 different ways to overlap two periods of time and I haven't checked for all of that. But I can modify that once I get a better understanding of what your formula did.

    Can you explain why there needs to be a $ in front of the Column Letter and a separate one in front of the Row Number? And I've seen the -- used before I don't quite understand it's meaning. Is that how we get the formula to loop and repeat itself?
    Thanks a bunch!

    =SUMPRODUCT(--($A$2:$A$30000<A2),--($B$2:$B$30000>A2))+1

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    Hi, glad it worked for you.

    the $A$2 (absolute reference) in a formula will always stay $A$2, even when the formula is copied across or down. The A2 (relative reference) will change to A3, A4, A5 etc. when copied down. In this formula I use the absolute reference for the range I want to check. This always needs to be A2 through to A30000, so I have to use absolute referencing when I copy the formula down. But in each row, I want to compare only the value in column A in the current row, so I use A2 in row 2, and when the formula is copied down, the relative reference will be adjusted to the current row.

    Now about the --
    A statement like $A$2:$A$30000<A2 returns either TRUE or FALSE. If I put the -- before the statement, it will translate TRUE into 1 and FALSE into 0, so I can actually use it for calculations. The SUMPRODUCT will multiply the results of each argument.

    In a formula with 7 instead of 30000 lines the part $A$2:$A$8<A2 may return {TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE}, which with the -- is then translated into {1, 1, 1, 0, 0, 0, 0}.

    the next argument $B$2:$B$8>A2 may return {FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE}, which with the -- is translated into {0, 1, 1, 1, 0, 0, 0}

    These two arrays will be multiplied
    {1, 1, 1, 0, 0, 0, 0} *
    {0, 1, 1, 1, 0, 0, 0}

    the first element of the first array is multiplied with the first element of the second array, the second element of the first array is multiplied with the second element ofthe second array, etc, and the result is

    {0, 1, 1, 0, 0, 0, 0}

    Sumproduct then adds up these results to return 2

    SUMPRODUCT is a very powerful formula, but it can take a while to internalise how it works.

    hth

  5. #5
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Hi teylyn,

    That's awesome. I was trying to figure out how to compare the value without the formulas changing. The absolute reference is perfect. Thanks for that tip.
    As for the array, basically you would have to have both the results be TRUE for the end result to be TRUE. That makes sense.
    So the SUMPRODUCT command repeats this calculation for however many results gets returned from the range of numbers chosen?

    OK, so time to kind of fine tune this calculation. My original test was insufficient to check for all the different ways two time lines might overlap.
    A1=call 1 start, B1=call 1 end
    A2=call 2 start, B2=call 2 end

    Overlap 1: A1 is between A2 and B2 (call 1 starts during call 2's interval)
    Overlap 2: B1 is between A2 and B2 (call 1 ends during call 2's interval)
    Overlap 3: A1 < A2 AND B1 > B2 (call 1 starts before and ends after call 2; basically this interval eclipses the other one)
    Overlap 4: A1 > A2 AND B1 < B2 (call 1 starts and ends while call 2 is ongoing; basically this interval is inside the other one)

    Test for Overlap 1
    =SUMPRODUCT(--($A$1:$A$30000<A1),--($B$1:$B$30000>A1))
    Test for Overlap 2
    =SUMPRODUCT(--($A$1:$A$30000<B1),--($B$1:$B$30000>B1))
    Test for Overlap 3
    =SUMPRODUCT(--($A$1:$A$30000>A1),--($B$1:$B$30000<B1))
    Test for Overlap 4
    =SUMPRODUCT(--($A$1:$A$30000<A1),--($B$1:$B$30000>B1))

    However, I unable to find a combination of formulas to test to see if ANY of the Overlap tests were TRUE

    I was thinking something like this but it doesn't work. It takes the results of the OR as a single computation. I can't get it to repeat the way SUMPRODUCT goes through the entire range.

    =OR(SUMPRODUCT(--($A$1:$A$30000<A1),--($B$1:$B$30000>A1)),SUMPRODUCT(--($A$1:$A$30000<B1),--($B$1:$B$30000>B1)),SUMPRODUCT(--($A$1:$A$30000>A1),--($B$1:$B$30000<B1)),SUMPRODUCT(--($A$1:$A$30000<A1),--($B$1:$B$30000>B1)))+1

    I thought about calculating each Overlap test separately but that won't work either because I'll be double/triple counting some numbers. That's because a scenario like Overlap 4 will match both Overlap 1 and 2 also. I just need it to register a single time if ANY of the tests are TRUE.

    Any ideas?
    Thanks a lot.
    Last edited by Yonkers; 05-20-2009 at 12:14 AM.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    Hi,
    don't have much time today, so just a thought, not tested:

    how about putting the four overlap sumproduct formulas in separate columns and use a fifth column to calculate the totals?

  7. #7
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    I thought about that but I don't think it will work.

    So we have 4 tests
    Overlap 1: A1 is between A2 and B2 (call 1 starts during call 2's interval)
    Overlap 2: B1 is between A2 and B2 (call 1 ends during call 2's interval)
    Overlap 3: A1 < A2 AND B1 > B2 (call 1 starts before and ends after call 2; basically this interval eclipses the other one)
    Overlap 4: A1 > A2 AND B1 < B2 (call 1 starts and ends while call 2 is ongoing; basically this interval is inside the other one)

    Say for example I have:
    Call 1 - Starts 9:00am Ends 9:05am
    Call 2 - Starts 8:50am Ends 10:00am

    Overlap 1 test is TRUE
    Overlap 2 test is TRUE
    Overlap 4 test is TRUE

    So basically the calls do Overlap. But if I add that up, it will show that Call 1 had three overlaps instead of just 1.
    I need to find a formula that basically says, test for Overlap 1. If TRUE then don't test anymore. If false then test for Overlap 2, etc. Basically it is an OR test of each individual SUMPRODUCT formula. But I'm not sure how to get this OR to work in down the Rows the way the SUMPRODUCT goes down the array.

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    Hi Yonkers,

    I think I've got it. I thought my head was going to explode, but it is really not that complicated.

    You need three checks only:

    1. Calls that start during the current call
    2. Calls that end during the current call
    3. Calls that start before and end after the current call.

    The fourth check is not necessary, because it will be covered by 1 and 2.

    Attached is a spreadsheet that lists 10 calls. I have created named ranges for the start and end date column, so it's easier to read and apply in formulas. A graph shows the start and duration of the calls, so it's easy to check if the formulas give the correct result.

    Now, in col G I calculate check 1: calls that start during my interval (including me)
    In col H I calculate check 2: calls that end during my interval (including me)

    These two checks form the bulk of the concurrent calls, but I really only need the biggest of these two calculations.

    On top of that I need to add calls that started before my interval and ended after my interval. This is calculated in column I

    In column J I put it all together manually and in column K it is all in one formula. You really only need column K, the rest is just to illustrate the elements of the formula.

    Try it and play around with the start and end times. The duration column is needed for the graph, so don't delete it.

    cheers
    Attached Files Attached Files
    Last edited by teylyn; 05-21-2009 at 07:34 PM.

  9. #9
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Wow. That's awesome teylyn. You're absolutely right about the 3 checks. Not sure why I totally overlooked that.
    I really appreciate you taking the time to create the spreadsheet. Everything was very clear and I totally understand how it's supposed to work.
    Weird thing is though, I put in the formula on my sheet and it worked for the first row. However, when I copied it down to the rows below, I got a #VALUE error. Haven't been able to troubleshoot it too much but so far it looks exactly the same so I have no idea why it's failing. I'll try replacing the name with the actual absolute value ranges.
    Thanks for your help and I'll let you know if I get it working.
    Last edited by Yonkers; 05-22-2009 at 12:01 AM.

  10. #10
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    hi yonkers, it's 8:30 pm on a Friday nite in NZ and I'm writing this on a crappy PDA lying in bed, so plz xcuse any typos or weird characters.

    I'm glad you find my formula useful. don't know why it throws the #value error, though. if I were to do it, I'd create range names for the start and end time columns and use these in the formula. If you're using daily logs where the number of cells in a column changes all the time, look into dynamic range names that are defined with a combination of OFFSET(9) and COUNTA() to always include all populated cells in a column.

    If you use range names you'll greatly reduce the risk of errors in the ranges used of the formula.

    I'm keen to know how you're doing. This has been an intriguing challenge and I'd like to know if you managed to solve it to meet your requirements.

    So, plz keep me updated and let me know if I can be of any more help. I'll be offline until Monday morning NZ time, though. My family needs me too.
    cheers & have a gr8 weekend

    teylyn

  11. #11
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Hi Telyn,

    It was a typo on my part when I created the range names. I forgot a $ in front of one of the numbers for the absolute reference. It confused me because it worked for the first row and not any of the others. Now the formula works on all rows. So thank you very much for that because I learned a whole lot from just trying to understand that formula.
    Now I'm trying to figure out how times I had 24 calls going on at once.
    So the criteria for this formula seems to be.

    1. Call_X overlaps with at least 24 calls and at least the 23 calls immediately after Call_X all overlap with at least 24 calls.

    =COUNTIF(C2:C25>24)

    And then copy that down? Seems like there should be something simple to calculate this, since the hard work has been done already. Still thinking this through but wanted to update you at least.
    Thank you very much and have a great weekend.

  12. #12
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    Hi Yonkers,

    I've had another think about the challenge, and I believe we're attacking it from the wrong angle, because we're not asking the right questions.

    Currently, we're asking: how many calls went on during the current call? Example: We have a 10 minute long call. During its duration there were 6 other short calls, none of the short calls overlapped:

    long call ******************
    short calls ** ** ** ** ** **

    The formula I've been working on would count 7 calls total. But that's not quite right. At any one point in time there were only ever two calls going on at the same time.

    Therefore, I think the question we need to ask is: When Call A starts, how many other calls are already going on?

    We really only need to look at the start of the call, because if during Call A another Call B starts, that Call B will then count its respective concurrent calls, including Call A.

    When you look at the chart I made in the previous post, the calls run horizontally and you want to know how often a vertical line crosses 24 calls. Draw that vertical line at the start of each call and you have your result.

    So, very simple formula to calculate calls going on at the same time (using the range names for the start and end times of calls):

    =SUMPRODUCT(--(B2>=callStarts),--(B2<=callEnds))

    In the attached workbook I've also build a little table to show the counts of the concurrent calls.

    Take some time to mull over that. It's not a simple challenge, but the solution actually is simple. I feel that looking at the chart helps to get a better feel for what needs to be analysed, and playing with the start and end times of calls will help visualise certain scenarios.

    Hope that helps

    teylyn
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Hi Teylyn,

    Sorry for the slow response. And thanks for mulling this over. I still haven't had a chance to digest all of what you wrote. I will do so tonight.
    But I wanted to reply and say that that I don't think our previous efforts were for naught. Our previous effort was to see how many other calls the current call overlapped with. Well, the only calls I care about are ones that overlap with at least 23 others. None of the calls with less than 24 overlaps will fit the criteria that I care about. So through our effort from last week, I was able to rule out 26k of the 30k calls. So we only need to work with 4k phone calls now
    Now I need some time looking at your most recent post.
    Thanks again.

  14. #14
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Figure out occurence of overlapping date & time

    Hi,

    in your original post you wrote
    My phone system can handle 24 concurrent calls. I'm trying to see how many times throughout the month did we have 24 or more calls going on at once.
    So, as I said above, althoug one single long call may during its duration overlap with 24 other calls, it may still be that these 24 calls are not active at the same time. You really want to see if 24 calls went on at the same time, which is not the same as overlapping with the current call.

    See the difference?

  15. #15
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Yes. I understand that I might have one call that goes on for 2 days and overlaps with 1000 different 1 minute long calls... and that still might not satisfy my criteria of 24 concurrent calls - if the 1000 calls are all consecutive instead of concurrent.
    However, my point is that when I DO have a situation where I have 24 concurrent calls then EVERY single one of those calls overlap with at least 23 other calls. There is never a situation where I would care about a call that overlaps with less. So by filtering out (or in rather) all calls that overlap with at least 23 others (which is what we did previously) I can start to narrow down my list of calls.
    Now I'm sitting at 4k calls (instead of 30k) and I can start to figure out which ones in that 4k happened at the same time.

  16. #16
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    Well, it seems like you've done it again. Your theory seems to bear it out. I ran that simple formula through all 30k calls and it looks like it gives me what I need.
    What I couldn't wrap my head around was why I didn't need to check if a call overlapped with other calls beyond the initial start. Meaning... a call might only overlap with 2 calls when it first starts but because it lasts 2 hours it ends up overlapping with more calls.
    But then I realized it didn't really matter. I just need to check when the initial call attempt is made. Because if I don't show that specific call as overlapping then the calls below it will capture the fact that was still ongoing, 2 hours later.
    I'm still working the logic through my head but it's beginning to make sense. And it ends up being so simple. Just like we suspected it would be.
    Thanks so very much.

    Edit: I just went back and read through your post and you basically said the same thing I just did. lol. Well, I never said I wasn't dense. I had to go through the logic myself before I could truly understand it.
    Last edited by Yonkers; 05-26-2009 at 09:43 PM.

  17. #17
    Registered User
    Join Date
    05-18-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Figure out occurence of overlapping date & time

    As an aside, can you explain how you created that chart? I looked at the properties of your chart and I tried to re-create it but I couldn't get the call # to show along the Y-axis and I couldn't get the time spaced out nicely like that along the X-axis. Also, I couldn't get the bars to show only when the call started etc.
    Thanks.

  18. #18
    Registered User
    Join Date
    11-15-2012
    Location
    Seattle
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Figure out occurence of overlapping date & time

    Hi, I have a most similar question that I cannot seem to work with formula. I have a list of just over 100 call log entries. I need to calculate how many calls have overlapped. Times are recorded in military time. Each list is based on a 24 hour period.

    Columns are:
    B. Start time
    C. Duration
    D. End time


    When I say overlapped, I mean:
    If any rows' start, elapsed/duration or end time is equal to any other rows start, elapsed/duration or end time.

    Any help is greatly appreciated.

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Figure out occurence of overlapping date & time

    Nicoleemily,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  20. #20
    Registered User
    Join Date
    03-04-2013
    Location
    Halifax NS
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Thank you so very much for this solution! I used it to calculate the maximum number of desks being utilized concurrently in a very popular space in a healthcare facility. This worked wonderfully.

    Thank you again. I had been struggling with pivot charts and vba for quite some time.

  21. #21
    Registered User
    Join Date
    06-10-2013
    Location
    dublin
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Hi

    From what i can see in the spreadsheet the actual number of concurrent calls is in column E and not F

  22. #22
    Registered User
    Join Date
    01-15-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Registered just to get this excel file, thank you very much... exactly what I needed!

  23. #23
    Registered User
    Join Date
    04-10-2014
    Location
    Saudi Arabia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Jus registered to download that file .Thanks mate

  24. #24
    Registered User
    Join Date
    12-04-2019
    Location
    canada
    MS-Off Ver
    office16
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    same, registered just to see the file. Thanks!!

  25. #25
    Registered User
    Join Date
    01-27-2020
    Location
    Chillicothe, Oh
    MS-Off Ver
    360
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Still going strong, registered just to see the file. Thanks!!

  26. #26
    Registered User
    Join Date
    04-28-2020
    Location
    New Orleans
    MS-Off Ver
    Version 1902
    Posts
    1

    Re: Figure out occurence of overlapping date & time

    Old thread but this is useful. There is however a difference between generating the number of overlapping events, and the number of Simultaneous overlapping events. The example shown in the thread is limited to only those events occurring simultaneously at the start of the event, but omits those that are still simultaneous (concurrent) after the start of the event. I have been trying to work through this issue myself with a related application regarding Pump reliability and overlapping out of service times. I need to know how many overlapping events (SOLVED), simultaneous overlapping events, and the cumulative time durations of those simultaneous overlapping events for each case of 2, 3, 4, 5, etc. simultaneous overlapping events. See attached. Any help would be greatly appreciated. There is a much shorter way to get simple overlapping events in my attachment. At the moment I'm a bit stuck on the simultaneous bit and summing the time of them.

    -FPEPRO
    Attached Files Attached Files

  27. #27
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: Figure out occurence of overlapping date & time

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed 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