Scenario:
I have an excel Timesheet which needs to calculate Standard Time 1x, Overtime 1.5x, Overtime 2x based on the following values:
If the start time and finish time fall between 08:00 and 16:45, then sum the hours x1
If the finish time falls between 16:45 and 00:00, then sum the hours by x1.5
If the finish time falls between 00:00 and 08:00 then sum hours by x2
Example Data:
Start time Finish time Standard time Overtime x1.5 Overtime x2
08:30:00 17:00:00 7.5 0.5 0
17:00:00 01:00:00 0 7 1
01:00:00 10:00:00 2 0 7
06:00:00 12:00:00 4 0 2
I have been racking my brain and possible ways to do this but keep falling short, does anybody know how I would go about creating a formula to do this kind of some?
Ah, I am too late as the other answer has been accepted which is great if it covers a 48-hour period. Anyway this is how mine looks - can provide some explanation later.
Here are the definitions relative to cell D2
So the basic formula is
=MAX(0,MIN(ClockOff+Split,ShiftEnd)-MAX(ClockOn,ShiftStart))
This is based on the standard formula for calculating the overlap of two ranges quoted in various places e.g. here but adds 1 (equal to one whole day) for the case when the end of shift is after midnight. This works for standard time (starting in D2) and overtime X 1.5 (starting in E2) as long as the end of the evening shift (in J4) is also entered as 1 whole day (24:00 hours). For overtime X 2, both the start of shift (0:00) and end of shift (08:00) have to be adjusted by 24 hours if the hours worked are split across midnight so the formula in F2 is
=MAX(0,MIN(ClockOff+Split,ShiftEnd+Split)-MAX(ClockOn,ShiftStart+Split))
Create a matrix of times and use an if statement to determine if the time falls within the shift or not. Sum the times as required for each shift.
Here's a link to my example http://www.scotlang.com/Overtime.xlsx.
Related
I created an Excel Spreadsheet with a Total Time for the Duration of the Shift ie 8:30-17:30.
Then I created this formula
=(MOD([#[Supposed Shift End]]-[#[Supposed Shift Start]],1))*24
with Format cells -> Number 2 decimal places. This gives me the [Total Supposed Shift Hours]
Giving me Duration of the Shift that needs to be covered.
Now I also created another column for the ACTUAL time the shift covered
=(MOD([#[Actual Time End]]-[#[Actual Time Start]],1))*24
This gives me the [Total Actual Time Hours]
For the Actual Time End and Actual Time Start When the employee DIDN'T show up we entered 0 for both cells with the same cell format Number -> 2 decimal places
The Problem:
This is the formula I wrote to subtract these 2 Columns
=(MOD([#[Total Supposed Shift Hours]]-[#[Total Actual Time Hours]],1))*24
Why when I subtract say the [Total Supposed Shift Hours] 9.00 - the [Total Actual Time Hours] 0.00 = 24.00 ???
9 - 0 = 9 not 24.... sigh
Will the formula be affected if the time goes from previous night 21:00 to 8:00 with the MOD formula?
Sample data (as requested)
Note: Nomenclature differs from description above: Open = Supposed and Covered = Actual
Service Date
Open Post Start
Open Post End
Total Hrs Missing
Covered Post Start
Covered Post End
Total Hrs Covered
Category
Hours Not Covered
02/06/2021
16:00
00:00
8
16:00
03:00
11
A
0
04/06/2021
16:00
00:00
8
00:00
00:00
0
A
0
10/21/2021
10:30
00:00
13.5
18:00
19:30
1.5
B
0
Initial Answer
A minor point first: You don't need to wrap the MOD function in brackets. As the function already produces a result to the *24. Thus the following works just fine:
=MOD([#[Supposed Time End]]-[#[Supposed Time Start]],1)*24
To your question: Your non-working formula reads as if it simply wants the difference (in hours) between Supposed and Actual. If that's so, simply do this:
=[#[Total Supposed Shift Hours]]-[#[Total Actual Shift Hours]]
EDIT: Using the (now posted) table, I've constructed what I think it is you're trying to doRefer to Sample results image below.
Formula in Colum E: =MOD([#[Open Post End]]-[#[Open Post Start]],1)*24
Formula in Colum H: =MOD([#[Covered Post End]]-[#[Covered Post Start]],1)*24
Formula in Colum J: =[#[Total Hours Missing]]-[#[Total Hours Covered]]
Sample results:
Now: If Column J (i.e. the response to your core question) isn't the result you're after, can you tell me what it is you would expect there (using actual expected values for each row).
Notes:
Your table column header Total Hours Missing is somewhat confusing.
But, I'm reading that a Post Duration (Duration of Shift in your original parlance).
If I understand what transpired correctly, the "spanner in the works" was #P.b suggestion to remove MOD. Revert your formulas in columns E and H as shown above.
I’m trying to create either a spreadsheet or macro that allows me to put and employee start and finish time in and then show me by each half hour how many half hours they are in.
For example;
Employee 1 - 08:30 to 10:15
The output I would want is;
08:00 0
08:30 1
09:00 1
09:30 1
10:00 0.5
10:30 0
11:00 0
So between 8:30 and 9:00 shows as one because that employee was in during that half hour. But between 10:00 and 10:30 it shows 0.5 because the employee was only in for half of that period
Then as I add more data it tells me which half hours they are covering.
I’ve tried using the ceiling and floor values, counta, countif, countifs, v and hlookups but just can’t get the desired effect.
I’m guessing it would need to be a macro.
Assuming C1 and D1 contain the start and end times of a shift and column A contains the times, use the following formula in column B:
=IF(A2>D$1,C2,IF(AND(A2>=C$1,A3<=D$1),1,MAX(0,A3-D$1)/(1/48)))
Limitations: shifts cannot cross over days, days cannot start before 00:00 or end after 23:59
I am in much need of help please.
I have the table below.
It has about 300 rows and columns on the right for each day of the year starting 2015, ending 2019. I only entered a few columns here as an example.
What I need:
A formula to split the time (it can be hours or decimal days, it doesn't matter) between the two days on the left on the columns to the right.
In the rest of the days, which are not included in the period, I need a zero in those columns.
I manually entered the results I need so it can help you understand.
E.g.
On the first row:
The employee has spent
15 hours at destination in the first day of travel,
24 hours in the second day of travel
11:50 hours in the last day of travel.
All the rest of the columns to the right, which are not here, starting 1/4/2015 23:59 should give the result zero.
Thank You!!
Entry Date Exit Date 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59
1/1/15 9:00 1/3/15 11:50 15.00 24.00 11.50
As far as I can tell, it boils down to this
1.0 days 2.0 days 3.0 days 4.0 days
period=p in h/d.d p-(1-(so far)) p-(2-(so far)) p-(3-(so far)) 0
EDIT 2: I've come up with a formula.
NOTE:
This formula assumes existence of a column that specifies 0 hours of work between the "end date/time" column ("B") and first work hour ("D"), so you have it like this:
A B C D E F G H
1 Entry Date Exit Date ZERO 1/1/2015 23:59 1/2/2015 23:59 1/3/2015 23:59 1/4/2015 23:59 1/5/2015 23:59
2 1/1/15 9:00 1/3/2015 11:50 0 0.6243055556 1 0.49375 0 0.00
3
The extra column is there to avoid circular dependencies, since
we must "iteratively" accumulate the hours
The main formula for row 2 from column D being:
=MIN(D1-$A2,MIN(MAX(($B2-$A2) - SUM($C2:C2), 0),1))
Note: semicolons may be needed instead of commas in Excel as delimiters.
Note: the last digit in the formula depends on the unit. Here it is in days decimal. If hours, put 24.
In plain English, for a cell
Calculate sum of hours/days decimal in the range C to wherever - 1
Subtract result from the difference between start and end (total hours)
If less than 0, put 0 (MAX(x, 0))
If more than 1, put 1 (MIN(x, 1))
Choose between the result, or the difference between current date and start time, if it is smaller
I am trying to do a time subtraction in excel of 30 minutes and I am running into a speed bump. So the table I have are as follows.
Table "Schedule"
Column 1 is day of the week (Mon-Sun) (formated as general, as this is plain text)
Column 2 is start time of the shift (formated as h:mm AM/PM)
Column 3 is end time of the shift (formated as h:mm AM/PM)
Column 4 is duration of the shift (start to end) (formated by formula (TEXT(col3-col2,"h:mm")) )
Column 5 is paid hours (if the total hours is over 6.5 then subtract 0.5 hours for an unpaid lunch) (formula IF(col5>"6:30",col5-"0:30",D5) )
The issue is any time allotment over 10 hours start to end (where column 4, the duration hits 10 hours) no lunch is subtracted at all.
So...
Start 9:00 AM, End 6:59 PM, Hours Total 9:59, Hours Paid 9:29
But...
Start 9:00 AM, End 7:00 PM, Hours Total 10:00, Hours Paid 10:00
and that should obviously not happen. I can't find anything on google so I figured the excel gurus here may have some advice.
Thanks!
If your time columns are stores using excel's dedicated time format, this should be straightforward. Mixed data types are likely your problem.
First, be sure your time columns (columns 2 and 3) are set using the time function, i.e.,
=time(hours,minutes,seconds)
Then, you should be able to add and subtract easily.
Column 4: = column 3 - column 2
... then subtract 30 minutes also using the time() function:
Column 5: = if(column 4 > time(6,30,0),column 4 -time(0,30,0),column 4)
Excel stores time values from 0 to 1. So 24 hours=1, 12 hours=.5 etc. That means 6.5 hours=0.270833333 and .5 hours=0.020833333. As a result you can just do a simple if statement.
=IF(D2>0.270833333,D2-0.020833333,D2)
To turn it into a time format, is to just use excel's time formating options.
Given a set of DateTime ranges in excel, such as:
Start Finish
13/03/2012 10:00:00 14/03/2012 03:00:00
15/03/2012 08:30:00 15/03/2012 10:00:00
And some TimeSpan such as:
Start Finish
07:00:00 09:00:00
How would you determine if the time span falls in some given date range?
An approach like this might be a start:
AND(B2 < DATEVALUE(TEXT(B2, "dd/mm/yyyy")) + TIMEVALUE("07:00:00"),
B3 >= DATEVALUE(TEXT(B3, "dd/mm/yyyy")) + TIMEVALUE("09:00:00"))
Though it relies on the being able to provide the start/finish values explicitly as opposed to two dates in any order. A conditional on start <= finish would do, but seems like it's overly complicated.
Is there a better way?
Edit: Bonus points for a simple approach to finding the percentage of the date range that falls in the time span
Seems like you're assuming that the dates will always be the same day, is that the case?
Try
=AND(MOD(A2,1)<=F2,MOD(B2,1)>=G2)
For percentage
=MAX(0,MIN(MOD(B2,1),G2)-MAX(MOD(A2,1),F2))/(B2-A2)
Update:
If the date range can be unlimited, 1 day or many, then you can use this formula to get the total hours within the timespan
=(INT(B2)-INT(A2))*(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2)
that assumes that the timespan doesn't cross midnight - if timespan may cross midnight, e.g. could be 08:00 - 11:00 but could also be 22:00 - 03:00 then this formula should work
=(F$2>G$2)*(B2-A2)+SIGN(G$2-F$2)*((INT(B2)-INT(A2))*ABS(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2))
This should give the number of hours falling in the time span (but it's definitely not simple!):
=MEDIAN(F2,G2+(G2<F2),MOD(B2,1)+(MOD(B2,1)<MOD(A2,1)))
-MEDIAN(F2,G2+(G2<F2),MOD(A2,1))
+(F2<G2)*(MOD(B2,1)<MOD(A2,1))*MAX(MIN(MOD(B2,1),G2)-F2,0)
If this is greater than 0, the date range falls in the time span, divide this by B2-A2 for the percentage.
e.g. Date Range: 6:00PM - 9:00AM, Time span: 7:00AM - 7:00PM returns 03:00 which is 20% of the date range.
Say the date ranges are in columns A and B, and the Timespan in F2 and G2.
Apply the following formulas and drag down.
H2 = IF(AND($F$2>=RIGHT(A2,8),$F$2<RIGHT(B2,8),$G$2>RIGHT(A2,8),$G$2<=RIGHT(B2,8)),1,0)
Column H gives tells you if it's true for a particular date range.
I1 = SUM(H2:H4)/COUNT(H2:H4)
I1 gives you the percentage