Calculate Overtime with IF statement

Comments

5 comments

  • Rainer Grabowski

    Hi Paul,

    Overtime you can calculate with:

    var wh = @Work Hours ;
    wh > 8 && wh <=12 ? wh - 8 : wh > 12 ? 12 : 0
    

    If wh = 10.5, the overtime result is 2.5, but if wh = 12.5, the result is 12.
    I'm not sure which result you expect if wh > 12.

    If you want to double time which is over 12 you can use:

    wh > 8 && wh <=12 ? wh - 8 : wh > 12 ? 4+ ((wh-12)*2) : 0

    Result for wh = 12.5 is 5 . Is that the result you expect?

    Rainer
    rg@delos-consulting.com

    0
    Comment actions Permalink
  • Paul Lyet

    Thanks Rainer.. Sorry. Wanst clear on that.. was simply looking for

    var th = @Total Hours;
    th > 12 ? th - 12 : 0

    I wanted to do a similar calculation off of @total hours that would simply show 8 hours if total time was > 8

    I thought it would just be

    var th = @Total Hours;
    th > 8 ? 8 : (else do nothing?)

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Paul,

    th > 8 ? 8 : ""
    

    Rainer

    0
    Comment actions Permalink
  • Paul Lyet

    Thanks again Rainer. This gives a result of 8 for any value over 8 and "" for any value under. What if I still want to return a lower value? 7 = 7 but 9 = 8

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Paul,

    th > 8 ? 8 : th
    

    if th = 9 -> result: 8, if th = 8 -> result: 8, if th = 7 -> result: 7

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk