+ Reply to Thread
Results 1 to 7 of 7

Logic test to calculate linear time difference crossover midnight - 2nd part not working??

  1. #1
    Registered User
    Join Date
    10-12-2013
    Location
    Blackwater, Australia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Logic test to calculate linear time difference crossover midnight - 2nd part not working??

    Hi Team.

    Using Excel 2007.

    I have made some progress on the spreadsheet issue that I was working on earlier. I decided to work on one portion at a time. If I can get the time calculation difference sorted then the rest should fall into place with some sleight of hand and some tricky conditional formatting. I have also posted this current post in my previous posting (Excel 2007 - Time difference calculations & automatic insertion of text in blank column) as it is essentially the same spreadsheet problem however I could not attach the new spreadsheet. (My apologies if this should have been kept within the previous thread only).

    Here goes...

    Algorithm #1
    =TEXT(S5,"00\:00")+(TEXT(Q5,"00\:00")<TEXT(S5,"00\:00"))-TEXT(Q5,"00\:00")

    The above algorithm works out the time differences over midnight between the scheduled arrival time and the actual arrival time however, to return the correct value; the scheduled arrival time must be later than the actual arrival time. This means the train arrived earlier than scheduled. If the train arrives later than scheduled the algorithm will return a value between 1 and 1439 depending on the earlier time. 1440 appears to be spot on time (ie zero (0) minutes).


    Algorithm #2
    =TEXT(S5,"00\:00")+(TEXT(Q5,"00\:00")>TEXT(S5,"00\:00"))-TEXT(Q5,"00\:00")

    The above algorithm works out the time differences over midnight between the scheduled arrival time and the actual arrival time however, to return the correct value; the scheduled arrival time must be earlier than the actual arrival time. This means the train arrived later than scheduled.

    If the train arrives dead on time both formulas return a zero (0) which is correct as the entered time (train) was neither early nor late.

    What I need is the above two formulas worked into one encompassing formula so that the time difference is returned regardless of the order of actual arrival time be it early, on time or late. I need excel to perform something similar to what follows as my logic is the train is either early or late (as spot on time using either version of the algorithm returns zero (0).

    My current formula (algorithm #4 below) however is giving me grief. I am currently stuck at the following where a dead on time returns FALSE instead of zero (0). Not really too much of an issue because by playing with the </> making them <= or >= returns a numerical value. However, to really bake the noodle, the second part of the logic test does not seem to kick in

    Algorithm #3
    =IF(TEXT(S5,"00\:00")+(TEXT(R5,"00\:00")<TEXT(S5,"00\:00"))-TEXT(R5,"00\:00"),TEXT(S5,"00\:00")+(TEXT(R5,"00\:00")>TEXT(S5,"00\:00"))-TEXT(R5,"00\:00"))

    As I said, adding an '=' so the </> changes to < or = to/> or = to returns a value of 1440 and not FALSE.

    Now the algorithm looks like this:

    Algorithm #4
    =IF(TEXT(S5,"00\:00")+(TEXT(R5,"00\:00")<=TEXT(S5,"00\:00"))-TEXT(R5,"00\:00"),TEXT(S5,"00\:00")+(TEXT(R5,"00\:00")>=TEXT(S5,"00\:00"))-TEXT(R5,"00\:00"))

    This returns the correct value for trains running late both prior to midnight and going past midnight, however the second part of the logic test does not seem to kick in for trains running early. Obviously there is something wrong with the algorithm here (even though Excel is accepting it) because if the time in column S is earlier than the comparison time in column R the first part of the logic test is obviously false, therefore should be skipped for the second part which is true.

    I know I am missing something really obvious here, but I just cannot see it. Any suggestions, tweaks or modifications to the formula would be greatly appreciated.

    Attached is the spreadsheet that I am banging away at with my workings on it.

    Thank you in advance.

    Delta
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    06-01-2013
    Location
    Northampton, England
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Hi

    Attached is an easy solution if you can include date in your actual column.

    If not, then you'll need to find a way to tell if your F16:J16 is 4hr early or 20hr late!

    Regards
    AC
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    10-12-2013
    Location
    Blackwater, Australia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Hi Alan,

    Thanks for your reply.

    Unfortunatly I have designed the spreadsheet for use by my collegues with as little input required as possile, hence arrival/departure times are even represented without the colon. This way what would normally be put down on paper and then manually worked out is input into the spreadsheet in exactly the same manner.

    You have however hit the nail on the head as finding a way to tell if your F16:J16 is 4hr early or 20hr late is here I am stumped.

    I did think that perhaps slaving the column to the computer clock date would solve the issue as the time frame we are looking at will never be more than 36 hours, but I ran into problems with this early on.

    It does work fine if, as you suggested, we include the date with this as well, however, there does not appear to be any way of having this work by just time input alone.

    My next bit of logic was to reduce all input into a number vairable and then simply reduce the first from the second and wrap an ABS() formula around it. No luck there hence the latest attempt with a logic test.

    As indicated, the first part works correctly if true. Just not sure why, if the first part is false, it does not follow through with the remainder of the logic which should switch the inputs around giving the same number as if it were linear.

    I am back at work on the 23rd and so will test your spreadsheet addition then.

    Thank you very much for your assistance with this.
    Last edited by Delta337; 01-20-2014 at 02:43 AM.

  4. #4
    Registered User
    Join Date
    10-12-2013
    Location
    Blackwater, Australia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Hi Alan,

    I have rejigged the data sheet so that dates and times are now included as you suggested. Your solution works like a charm except that the on time running for trains is + or - 15 minutes either side of the scheduled departure.

    How would you work that into your formula?

  5. #5
    Registered User
    Join Date
    06-01-2013
    Location
    Northampton, England
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Hi

    Let me know if Sheet2 works for you.

    Regards
    AC
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-12-2013
    Location
    Blackwater, Australia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Hi Alan,

    Works like a charm. I have taken the liberty of modifying your formula to suit my entire spreadsheet - Attached.

    I would love to know how the +/- formula works or how you got 0.010416667 as a 15 minute decamal vairiance.

    One last question.

    To make the sheet work in a copy and paste scenario raw numbers from one spreadsheet will be dumped into the "Data Dump" sheet in the attached spreadsheet.

    This means that if it is a slack day and there are only a few trains running, the spreadsheet is still calculating the blanks. As all trains have a Service Number, this means that the spreadsheet does not need to calculate any row where cells in column A are blank. This however is not a fixed number and trains services vary on a day to day basis.

    I can deal with this by using a conditional format like row 23, but I will have to do this for every row in the sheet for each appropriate column.

    I am stuck now on wrapping some form of logic test around your =MAX(D24,E24)-MIN(D24,E24) formula to tell it not to calculate if column A is blank. The error I keep getting indicates that the logic is incomplete.

    Thank you for your assistance so far. It is awesome. You and the team never cease to amaze me.

    Kind regards

    Delta

  7. #7
    Registered User
    Join Date
    10-12-2013
    Location
    Blackwater, Australia
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Logic test to calculate linear time difference crossover midnight - 2nd part not worki

    Sorry, forgot to attach curent working spread sheet.

    Regards
    Attached Files Attached Files

+ 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. formula to calculate time difference crossing midnight
    By ditorejax in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-06-2014, 08:27 PM
  2. [SOLVED] Calculating difference in time after midnight
    By alan peele in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-16-2013, 02:01 AM
  3. difference between times not working for after midnight.
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2013, 01:47 AM
  4. Replies: 1
    Last Post: 09-13-2012, 05:50 AM
  5. Replies: 0
    Last Post: 09-13-2012, 05:28 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