+ Reply to Thread
Results 1 to 5 of 5

Formula result not as expected. Elapsed Time Comparison.

  1. #1
    Registered User
    Join Date
    12-05-2018
    Location
    San Jose, CA
    MS-Off Ver
    2016
    Posts
    5

    Angry Formula result not as expected. Elapsed Time Comparison.

    I have the following columns and need to check if the elapsed time between 2 times are within 15 minutes +/- 2 minutes.

    Please see the attached spreadsheet.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Formula result not as expected. Elapsed Time Comparison.

    This looks like floating point error. When I use the Evaluate formula tool on D3, (https://support.office.com/en-us/art...6-a70aa409b8a7 ) I see:

    1) The value in C3 is 0.00902777777777763.
    2) The value from the TIME() function is 0.00902777777777778 (a difference of about 12 picoseconds).
    3) 63 is not >= 78, so this boolean expression returns FALSE. Of course, once one argument in and AND() function returns FALSE, the whole thing will return FALSE.

    Solutions to most floating point errors usually involve another rounding function. Decide what precision you need to actually test for, and then nest your values inside of an appropriate ROUND() or MROUND() function. Your entries are all to the nearest minute, so, if I assume that 1 minute is sufficient precision, I might nest the current formula in C inside of an MROUND() function =MROUND(current_formula,TIME(0,1,0)), which will round the current value to the nearest minute. This changes the result in D4 to TRUE.
    Last edited by MrShorty; 08-09-2019 at 07:14 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Formula result not as expected. Elapsed Time Comparison.

    Quote Originally Posted by MrShorty View Post
    =MROUND(current_formula,TIME(0,1,0)), which will round the current value to the nearest minute
    Although =MROUND(MOD(B3-A3,1),TIME(0,1,0)) seems to work for all times in A3 and a difference of 0:13 or 0:17 in B3, it does not work, for example, when A3 is 1:01, B3 is 2:14, and the formula in D3 is =AND(C3>=TIME(1,13,0),C3<=TIME(1,17,0)).

    In general, MROUND is unreliable when the second parameter is not an integer, for the same reason that MOD(B3-A3,1) did not work, namely: binary floating-point anomalies.

    IMHO, it is more reliable to use the following to round time to the minute, when the entered time is accurate to the minute: =--TEXT(MOD(B3-A3,1),"h:m") . The double-negate converts text to a numeric value.

    -----

    BTW, even though the comparison in C2 seems to work, it is only because Excel comparison operators (e.g. "<=") round the left and right operands to 15 significant digits.

    If the formula had been written in the form =AND(C2-TIME(0,13,0)>=0,C2-TIME(0,17,0)<=0) , which is mathematically equivalent, the formula would return FALSE.

    Even though both C2 and TIME(0,17,0) appear to be 0.0118055555555556 because Excel formats only the first 15 significant digits (rounded), in fact, C2 is infinitesimally larger; namely about 6.94E-17 larger.

    In this case, we can see that difference with the formula =C2-TIME(0,17,0) formatted as General or (better) Scientific.

    But often, we need to use a formula of the form =C2-TIME(0,17,0)-0 . The redundant -0 avoids another anomaly that is specific to Excel arithmetic, namely: sometimes, if the last difference of a formula is "close to zero" (a misnomer), Excel replaces the actual difference with exactly zero.

    The point is: we cannot always rely on a visual comparison of the formatted values in order to understand why arithmetic and comparison operations do not give us expected results.
    Last edited by joeu2004; 08-10-2019 at 04:02 PM. Reason: typo: C3 s.b. D3

  4. #4
    Registered User
    Join Date
    12-05-2018
    Location
    San Jose, CA
    MS-Off Ver
    2016
    Posts
    5

    Re: Formula result not as expected. Elapsed Time Comparison.

    Thank you both for the valuable replies!!!

    I have used =--TEXT(MOD(B3-A3,1),"h:m") in my formula and all seems well. 1500 calculations and all were as expected!! Thank you so much for the quick replies!!!!

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,719

    Re: Formula result not as expected. Elapsed Time Comparison.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    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.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. [SOLVED] Joining to formula not given expected result
    By Excelski in forum Excel General
    Replies: 6
    Last Post: 12-20-2018, 08:32 AM
  2. Replies: 3
    Last Post: 04-30-2018, 11:46 PM
  3. [SOLVED] INDEX MATCH formula not returning expected result
    By lukela85 in forum Excel General
    Replies: 4
    Last Post: 12-18-2017, 11:23 AM
  4. [SOLVED] Match formula does not return expected result?
    By Aland2929 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-05-2017, 10:56 AM
  5. [SOLVED] Index - Match formula not giving me an expected result
    By longbow007 in forum Excel General
    Replies: 5
    Last Post: 11-25-2015, 07:34 PM
  6. Elapsed time negative result
    By OllieKP87 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-02-2014, 02:30 PM
  7. [SOLVED] Logical Formula with comparison operator not behaving as expected
    By attal in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-26-2013, 02:13 PM

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