Calculate Overtime with IF statement
I currently have a calculation using two date fields "start time" and "end time along with a lunch duration field to give me a total hours for a work day but now I would like to add two more calculation fields to break out overtime and double overtime. My current calculation looks like this:
var t1 = moment(@Start Time);
var t2 = moment(@End Time);
var t3 = @Lunch Duration;
var result = t2.diff(t1, 'hours') - t3;
result;
I'm thinking my next calculation would be something like: if @Work Hours >8 and <=12 then - 8 if >12 = 12 ??
And Double would just be if @Work Hours >12 then - 12
Anyone have an idea?
-
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 -
Thanks Rainer.. Sorry. Wanst clear on that.. was simply looking for
var th = @Total Hours;
th > 12 ? th - 12 : 0I 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?)
Please sign in to leave a comment.
Comments
5 comments