+ Reply to Thread
Results 1 to 4 of 4

Formula to calculate hours that are positive and negative

  1. #1
    Registered User
    Join Date
    05-27-2022
    Location
    England
    MS-Off Ver
    MS Office 365
    Posts
    18

    Exclamation Formula to calculate hours that are positive and negative

    Hi.

    I've spent the best part of this morning figuring out formula to get where I have for a timesheet to track my hours at work. I have managed to get everything working including getting negative hours to show without selecting the 1904 date system as it breaks other sheets in my workbook.

    As you can see I have got my contracted hours and then the hours worked. This has calculated whether I am over hours or under hours each day. The part that I really can't get working is to calculate the total hours in that week as some days are positive hours so I have worked more than my contract and some days are negative hours so I have worked under my contract. I would like a formula to calculate the total weekly hours based on working more or less hours if that makes sense? I have tried everything that I know off and Google isn't getting the results I am after.

    I have attached the workbook as well as two pictures showing what it looks like and the formula view.

    I appreciate all your help. Have a good day.

    Asda Wages.png
    Asda Wages Formula.png
    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,827

    Re: Formula to calculate hours that are positive and negative

    The problem is that Excel's time formatting cannot display negative times. Are you required to use Excel? Of the spreadsheets in common use, LO Calc and Google Sheets have both decided that this is a stupid limitation and have programmed their spreadsheets to readily display negative elapsed times. I believe the easiest solution to this problem is to drop Excel like a hot potato and move to a different spreadsheet. Then you can store your elapsed time differences as numbers (formula in column H is simply =F7-D7 formatting as elapsed time rather than time of day), and the spreadsheet can easily sum those numbers.

    If you are required to use Excel, then are you required to display in sexagesimal time format? If you use a formula like =F7-D7 in column H, the number will be correct -- the only limitation is that Excel cannot display it in a sexagesimal time format. If you can tolerate seeing the numbers as decimal days rather than sexagesimal time format, then you can format column H as general or similar and not worry about the limitations on number/time formatting.

    If you must see the sexagesimal times, then I think the easiest way to do this is to add a helper column (possibly hidden if you don't want to see it) where you store the time difference as numbers (=F7-D7) summed at the bottom just as you are now =SUM(I7:I10) (assuming you use column I for this helper column). Then your formula in H11 becomes =IF(I11<0,"-","")&TEXT(ABS(I11),"[hh]:mm"). Note that I used an elapsed time format (the square brackets around the hh) rather than a time of day format. If this value will never be larger than 1 (24 hours), then it won't make a visible difference, but I find that I want to make sure that I am specific in my programming so that, if for no other reason, I am clear in my own mind what time represent time of day and which ones represent elapsed time.

    What do you think of those options?
    Last edited by MrShorty; 05-27-2022 at 09:24 AM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Formula to calculate hours that are positive and negative

    Personally. I'd advise against using hh:mm with negative sign.
    My preference is to display +/- duration value in either hours or minutes.
    Ex:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then use standard arithmetic to calculate total up/down.

    But if you need to calculate total as is. You just need to follow your formula construct and replace cell references with SUM(Column).

    Ex:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    05-27-2022
    Location
    England
    MS-Off Ver
    MS Office 365
    Posts
    18

    Re: Formula to calculate hours that are positive and negative

    Quote Originally Posted by CK76 View Post
    Personally. I'd advise against using hh:mm with negative sign.
    My preference is to display +/- duration value in either hours or minutes.
    Ex:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then use standard arithmetic to calculate total up/down.

    But if you need to calculate total as is. You just need to follow your formula construct and replace cell references with SUM(Column).

    Ex:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Hi.

    Thank you so much for making it easy to understand. The formula "=IF(SUM(F7:F10)-SUM(B7:B10)>0,TEXT(SUM(F7:F10)-SUM(B7:B10),"hh:mm"),"-"&TEXT(ABS(SUM(F7:F10)-SUM(B7:B10)),"hh:mm"))" works perfect to get the total hours worked. I have tried to apply your response for each day based on if hours are under or over contract, but my response isn't coming out as expected even if I can the cell format.

    I think for the basic needs I need, I think I may be alright with the formula to calculate the weekly hours of up and down. It would be nice to have a better display of daily up or down, but it's not too important as the result I get is sufficient. I was thinking of using conditional formatting or something else to get the daily up/down, but my knowledge on this isn't great. My excel knowledge is OK, but on this topic it's a little confusing.

    Thanks again for your help.

+ 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. Replies: 6
    Last Post: 02-11-2022, 08:01 PM
  2. Replies: 12
    Last Post: 04-22-2018, 05:11 PM
  3. [SOLVED] Calculate the positive or negative net
    By GigaFluxx in forum Excel General
    Replies: 2
    Last Post: 02-05-2015, 12:57 PM
  4. Formula calculate based on negative or positive number
    By oxicottin in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-15-2012, 12:45 PM
  5. Formula to calculate difference between a negative and positive number.
    By zumwaj01 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-25-2012, 02:13 PM
  6. [SOLVED] how to calculate difference in two columns either positive or negative ?
    By spandan21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-29-2012, 10:40 AM
  7. Replies: 3
    Last Post: 02-03-2007, 01:35 AM

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