+ Reply to Thread
Results 1 to 12 of 12

Time intervals SUM unexpected result

  1. #1
    Registered User
    Join Date
    06-04-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2010
    Posts
    5

    Time intervals SUM unexpected result

    Hi all,

    I have this sheet where I calculate the daily time worked based on the sum of time intervals and then calculate the time effectively worked against an expected time value. Based on the final result I present, through conditional formatting, the difference in bold red if time worked was less than the expected, black normal if they're equal and bold black if time worked is greater.

    For instance:
    [Morning time equals the sum of up to 2 intervals)]
    N1 = (C1-B1)+(E1-D1)

    [Afternoon time equals the sum of up to 4 intervals]
    O1 = (G1-F1)+(I1-H1)+(K1-J1)+(M1-L1)

    Daily time equals the sum of morning time and afternoon time
    P1 = N1+O1

    Expected time
    Q1

    Difference between worked time and expected time
    P1-Q1

    The problem is that when "apparently" the time worked is equal to the expected time and the subtraction of the 2 shows ZERO, the SIGN function doesn't return ZERO as expected.

    First I thought the problem was with the SIGN function so I replaced P1 result with a literal value equal to Q1 and the result of the SIGN function was zero as expected. No problem here.

    So the problem must be in the sum of the periods of time. Apparently although:
    -the result of the sum shows the same value as Q1 and
    -the subtraction of the 2 returns ZERO and
    - if I test one value against the other it returns TRUE
    they are not exactly the same.

    All cells are formatted as "Time" of type "13:30".

    I'm running out out of ideas as what can be the origin of this difference. Although I'm not giving up on solving it myself, I have to admit that some help would be appreciated.

    Thanks on advance,
    ND

  2. #2
    Valued Forum Contributor
    Join Date
    04-03-2012
    Location
    East Sussex, UK
    MS-Off Ver
    Excel 2003:2010
    Posts
    893

    Re: Time intervals SUM unexpected result

    Could you post an example to show how it's 'going wrong'?
    If I've been of help, please hit the star

  3. #3
    Registered User
    Join Date
    06-04-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Time intervals SUM unexpected result

    Here goes.

    Morning worked time
    (12:50-9:35) = 3:15
    Afternoon worked time
    (18:45-14:00) = 4:45
    Daily worked time
    3:15+4:45 = 8:00
    Expected work time
    8:00
    Difference between worked and expected time
    8:00-8:00 = 0

    If I use the SIGN function on the subtraction, I get -1 instead of the expected 0
    SIGN(8:00-8:00) = -1

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

    Re: Time intervals SUM unexpected result

    Please post a small sample sheet with the figures you really use ( BTW why do you need the SIGN function?)

  5. #5
    Valued Forum Contributor
    Join Date
    04-03-2012
    Location
    East Sussex, UK
    MS-Off Ver
    Excel 2003:2010
    Posts
    893

    Re: Time intervals SUM unexpected result

    I've tried setting it up as you've described and I get 0.

    My question (as per Pepe's) is why would you use the SIGN function for this?

  6. #6
    Registered User
    Join Date
    06-04-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Time intervals SUM unexpected result

    If time is less than zero it is not displayed.

    So I use ABS function to show both negative and positive time values and the SIGN function to determine the formatting. Bold Red if "-1", Bold black if "1".

  7. #7
    Valued Forum Contributor
    Join Date
    04-03-2012
    Location
    East Sussex, UK
    MS-Off Ver
    Excel 2003:2010
    Posts
    893

    Re: Time intervals SUM unexpected result

    I think a sample workbook would be a good idea.
    I cannot work out without seeing one why the time would be less than zero.

    It may be easier to work out the time difference in a different way than you are and thus would negate the need to use SIGN.

    Couldn't guarantee that without seeing a sample though.

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

    Re: Time intervals SUM unexpected result

    Probably got to do with the underlying value not being what OP thinks it is

  9. #9
    Registered User
    Join Date
    06-04-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Time intervals SUM unexpected result

    Here goes an example workbook (I hope)
    Attached Files Attached Files

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

    Re: Time intervals SUM unexpected result

    Probably something to do with floating point arithmetic and how XL stores numbers

  11. #11
    Valued Forum Contributor
    Join Date
    04-03-2012
    Location
    East Sussex, UK
    MS-Off Ver
    Excel 2003:2010
    Posts
    893

    Re: Time intervals SUM unexpected result

    Change the formula in M4 to =SIGN(L4) and copy down. That way you will get the correct result for your conditional formatting.

    There are ways to make Excel show negative times, but if my memory serves me well, you cannot use the results in subsequent calculations so it's of little use if you need to do that.

    Let me know if the above idea works for you.

  12. #12
    Registered User
    Join Date
    06-04-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Time intervals SUM unexpected result

    Thank you Pepe Le Mokko.
    Thank you Spencer101.

    You were right Pepe. It had to do with the floating point. I rounded the values before the subtraction and it solved the problem (so it seems).

    Spencer, I tried your sugestion and it worked fine in the example I posted but it didn't work on the real sheet. The formula there is a bit more complex because it takes extra stuff in to consideration.

    Thank u both for the quick replies.

    Hope I can return the favour in the future.

+ 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