+ Reply to Thread
Results 1 to 9 of 9

Knowing if a time value is between two other time columns

Hybrid View

  1. #1
    Forum Contributor heytherejem's Avatar
    Join Date
    07-06-2017
    Location
    Hampshire, England
    MS-Off Ver
    2016
    Posts
    152

    Knowing if a time value is between two other time columns

    I have a table containing two times, a start and a finish time for various jobs.
    I have a second table containing the start time of other jobs, and my aim is to look at each start time in Table2, and see if it clashes with the times in Table 1.
    So I want to look at each time in Table 2 and compare to all the times in Table 1. The result should be a Y for if the time in table 2 clashes with a time in table 1, and a N if it does not clash.

    Attaches is the data, I tried a IF(AND but it doesn't seem to be acknowledging the times correctly and is giving a N when it shouldn't.

    Please help!
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Knowing if a time value is between two other time columns

    Use the following formula in a new column of your second table:

    Formula: copy to clipboard
    =IF(COUNTIFS(Table32[Time Started],"<="&2+[@ScheduleStartTime],Table32[TimeCompleted],">="&2+[@ScheduleStartTime])>0,"Y","N")
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor heytherejem's Avatar
    Join Date
    07-06-2017
    Location
    Hampshire, England
    MS-Off Ver
    2016
    Posts
    152

    Re: Knowing if a time value is between two other time columns

    @Olly,

    Thanks for the formula, i've applied it and it's working, but it's given 17 'N' and some of them are within the [Time Started] & [TimeCompleted] such as cell I5 where the scheduled start time is 20:50:00 and which clashes with almost all the dates in Table32. And I9 is 22:00:00 which also clashes with most of them.
    I can only see these two examples as incorrect, but any idea why this might have happened? I can attach the data again if needs be...

    Thanks!
    Jemma

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,463

    Re: Knowing if a time value is between two other time columns

    And BTW, contents of col E are text, not real time

  5. #5
    Forum Contributor heytherejem's Avatar
    Join Date
    07-06-2017
    Location
    Hampshire, England
    MS-Off Ver
    2016
    Posts
    152

    Re: Knowing if a time value is between two other time columns

    Hi Pepe, so if [ScheduleStartTime] in Table25 is within the time frame between [Time Started] and [TimeCompleted] in Table32 then I want to highlight these.
    I know Total Duration is text and I forced Time Started to be 20:00:00 as it's there or thereabouts for every run.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Knowing if a time value is between two other time columns

    Please try at I2 and drag down

    =IF((H2>MOD(MIN(Table32[Time Started]),1))+(H2<MOD(MAX(Table32[TimeCompleted]),1)),"Y","N")

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,463

    Re: Knowing if a time value is between two other time columns

    What do you mean by "clashes"?

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Knowing if a time value is between two other time columns

    Your data is a little tricky.

    Your times in the first table include a date element - this is how we know the TimeCompleted (e.g. 04:31) is actually AFTER the Time Started(e.g. 20:00)

    The ScheduleStartTime in the second table doesn't have a date element - so we need to add a date part to it... this is why I tried using 2+[@ScheduleStartTime] However, that logic isn't quite right. Looks like we need to determine when you consider a day starts - as you're not treating midnight as the start of a new day.

    So - given the time ranges, I'm guessing we can assume 12:00 midday is a reasonable cutover. We can build this in to the formula, to give us:

    Formula: copy to clipboard
    =IF(COUNTIFS(Table32[Time Started],"<="&IF([@ScheduleStartTime] < TIME(12,0,0),2,1)+[@ScheduleStartTime],Table32[TimeCompleted],">="&IF([@ScheduleStartTime] < TIME(12,0,0),2,1)+[@ScheduleStartTime])>0,"Y","N")


    That's pretty horrible!

  9. #9
    Forum Contributor heytherejem's Avatar
    Join Date
    07-06-2017
    Location
    Hampshire, England
    MS-Off Ver
    2016
    Posts
    152

    Re: Knowing if a time value is between two other time columns

    Hi Olly, you are completely right. I figured out the date was important when I tried to create a graph of the data which failed miserably. Thanks for this, it totally makes sense!

+ 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. Macro to Convert Time Format and Filter Into Columns By Time
    By dizjackson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2018, 06:40 PM
  2. Replies: 1
    Last Post: 06-05-2015, 06:57 AM
  3. Merge date and time columns without loosing time
    By robhargreaves in forum Excel General
    Replies: 7
    Last Post: 07-11-2014, 09:25 PM
  4. [SOLVED] Calculate Time from different Date and Time columns
    By Siddps in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-01-2013, 09:23 AM
  5. Replies: 2
    Last Post: 05-25-2012, 02:27 PM
  6. Replies: 2
    Last Post: 04-19-2012, 10:34 PM
  7. Replies: 7
    Last Post: 12-18-2008, 01:41 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