+ Reply to Thread
Results 1 to 11 of 11

Thread: how to sum negative times?

  1. #1
    Registered User
    Join Date
    01-17-2012
    Location
    germany
    MS-Off Ver
    Excel 2010
    Posts
    11

    how to sum negative times?

    I am trying to set up a time registration for work. Now I've come pretty far but I have problems with some little or rather big formulas.
    Let's say I have 2 cells. Each containing a time. The first contains my entire overtime and the second contains the overtime of the current day. Now of course it is no problem if the times are both positive. But if one day I work 1 hour less than I should, I have -01:00. I already found out a formula for the negative time, this is not the problem. But now I don't know how to continue. How to sum up this negative overtime. I think I have to work with an IF formula, since I have to cover each possible case (both positive, both negative, or one positive, one negative...)

    I have tried a bit and the best I found for now is :

    =IF(AND(H6>0;G7>0);H6+G7;IF(AND(H6>0;G7<0);TEXT((H6*24-ABS(G7*24))/24;"[hh]:mm");IF(AND(H6<0;G7<0);TEXT(ABS(H6)+ABS(G7);"-[hh]:mm"))))

    assuming H6 is the total overtime and G7 the overtime of the current day. Now for both positive this works. But as you can see, I tried 2 different methods to handle the negative time. First is the *24/24 and the second (but I'm not sure if I used this one the right way) is the ABS formula.
    Now of course I'm still missing the 4th case: IF H6<0 and G7>0 but I just couldnt be bothered to kill my time with this after the failure with the other formula.

    Sorry I know this is a little bit complicating, but it's actually the first time I work with Excel formulas. I hope you understand my question, I know it might be confusing. But well... Thanks in advance for your help!!

  2. #2
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,257

    Re: how to sum negative times?

    It would be helpful if you attach your file.

    Is there some reason that

    =H6+G7

    doesn't give the result you want? You are changing the negative number to positive, then explicitly determining the sign, but a simple addition will do the same thing.
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  3. #3
    Registered User
    Join Date
    01-17-2012
    Location
    germany
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: how to sum negative times?

    No it doesn't work with just a simple addition.

    I've attached the file now. It's a little bit complicated file, since it uses 2 other documents for the formulas.
    It's in German, but the formulas are in English.. I hope it doesn't confuse you!
    I know I still have a lot to work on there, but I hope you understand my problem and know maybe what to do!

    Thanks
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: how to sum negative times?

    Hi,

    in order to manage negative times, you could change formulas and format as number the results in column G.

    in G6 and below:

    =if(isnumber(E6*F6),E6*24-F6*24,0)

    in H6 to convert numbers into hours

    =if(G6<0,Text(H5+G6/24*(-1),"[hh]:mm"),H5+G6/24)

    You could also switch to date system 1904, but you could have to deal with other unexpected issues.

    I hope it's a little step forward.

    Regards
    Grüße
    Attached Files Attached Files
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

  5. #5
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,257

    Re: how to sum negative times?

    I was unaware of this issue because I have never tried to do time arithmetic that results in a negative time, but it doesn't work using the 1900 base time system that Excel uses. The solution of using the 1904 system will work, described here: http://j-walk.com/ss/excel/usertips/tip051.htm However, it also requires you to apply this option to your other workbooks with linked data, and I don't know if that is feasible for you.

    So your basic idea is correct. One way to generalize the formula would be

    =IF((E35-F35)<0,"-","")&TEXT(ABS(E35-F35),"[hh]:mm")

    Then you don't have to consider every combination of negative and positive values.

    Two other things:

    First, your formula in column E may not be doing what you expect:

    =IF(ISBLANK(OR(B6,C6,D6)),"",TEXT(C6-B6-D6,"hh:mm"))

    I suspect you want to test whether B6 is blank, or C6 is blank, or D6 is blank. That is not what this does. It first calculates a logical value for the expression

    OR(B6,C6,D6)

    and then tests whether the result is blank. The result will be either TRUE or FALSE, but it will never be blank. Therefore the formula always tries to do the subtraction and produces a #VALUE error when any of the values are blank. I think you want

    =IF(OR(B6="",C6="",D6=""),"",TEXT(C6-B6-D6,"hh:mm"))

    Second, you are creating time as a string in column F. Although this technically works, because Excel will convert it when you do a calculation, I would prefer that it be an actual time value. This formula will give you the same result but with a time value instead of a string. The 0 is 00:00 and 7.5/24 gives the time value for 07:30.

    =IF(WEEKDAY(A36)=1,0,IF(WEEKDAY(A36)=7,0,IF(WEEKDAY(A36)=2,7.5/24,IF(WEEKDAY(A36)=3,7.5/24,IF(WEEKDAY(A36)=4,7.5/24,IF(WEEKDAY(A36)=5,7.5/24,IF(WEEKDAY(A36)=6,7.5/24)))))))
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  6. #6
    Registered User
    Join Date
    01-17-2012
    Location
    germany
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: how to sum negative times?

    Thanks for this. You both helped me alot already with some formulas I wasn't exactly aware of problems.
    @Canapone: I used the formulas for G and H as you suggested. But the problem I still have is that it doesn't sum correctly. It simply adds the value of the times. See, if I don't work one day, I get -7 hours "overtime". Before that I maybe had 10 hours overtime. So logically I should have 3 hours remaining. But your formula just adds the 7 hours to the 10 and then I have 17.

    I just took some random numbers now to explain my problem. You see my problem is the H column. Do you maybe have an idea?

    @6StringJazzer: I can't use the 1904 format since I have 4 other files that work with this one, so unfortunately I somehow have to find another solution for this problem.

    Thanks alot

  7. #7
    Registered User
    Join Date
    01-17-2012
    Location
    germany
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: how to sum negative times?

    Thanks for this. You both helped me alot already with some formulas I wasn't exactly aware of problems.
    @Canapone: I used the formulas for G and H as you suggested. But the problem I still have is that it doesn't sum correctly. It simply adds the value of the times. See, if I don't work one day, I get -7 hours "overtime". Before that I maybe had 10 hours overtime. So logically I should have 3 hours remaining. But your formula just adds the 7 hours to the 10 and then I have 17.

    I just took some random numbers now to explain my problem. You see my problem is the H column. Do you maybe have an idea?

    @6StringJazzer: I can't use the 1904 format since I have 4 other files that work with this one, so unfortunately I somehow have to find another solution for this problem.

    Thanks alot

  8. #8
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: how to sum negative times?

    Edit:

    I sent the same message twice by mistake.

    Sorry
    Last edited by CANAPONE; 01-23-2012 at 01:36 PM.
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

  9. #9
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: how to sum negative times?

    Hi,

    maybe in column H formulas you would not need to multiply by (-1) g6/24

    In H6 and below you could try a small correction:

    =H5+G6/24
    Again, in column H you cannot have negative cumulative hours.

    You could transform times in numbers.

    ---------------

    Other subject: in E6 and below if you have to deal with times over midnight (or nightshift), just add (b6>c6)

    =if(Not(isnumber(B6+C6-D6+(B6>C6))),"",C6-B6-D6+(B6>C6))

    Hope it helps
    Last edited by CANAPONE; 01-24-2012 at 02:14 AM.
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

  10. #10
    Registered User
    Join Date
    01-17-2012
    Location
    germany
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: how to sum negative times?

    I really appreciate your help. I hope I'm not annoying you with this topic, it seems to be unsolvable for me.
    My question is: Why can't I have negative cumulative hours? Is there no possible way? I mean, maybe it's possible to add a column in between where I convert the time into text, calculate it that way, and then in the next column (which would be equal to the H column now) I re-convert the (now maybe negative text) into time...
    you know what I mean?

    Thanks again!

  11. #11
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: how to sum negative times?

    Ciao, no problem. You could add an helper column (J in example) in order to manage cumulative negative hours.
    You could hide this column and in column H have only visually negative times.

    I've used

    =IF(J6>0,J6/24,"-"&(TEXT(-J6/24,"H.MM")))
    In the attachment red formulas have been adjusted a little.

    Hope it helps.

    Regards
    Attached Files Attached Files
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

+ Reply to 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.2.0