How do I add a unit suffix to the hours an employee has worked? - excel

I'm looking for a formula to count hours and set up a shift plan
My idea is for managers, front of house and back of house to have their own planner.
Where I fall at is when I try to count hours for each staff member BUT also make it legible to the reader when printed
For example
Staff member 4 does
0830-1600 with an hour break on Monday
1200-1900 with no break on Tuesday
I want it to look like 0830-1600, but in the total hours to count out the whole week from the times put in each day

I think you need to re-design your calendar. Excel loves raw data to be split out onto separate rows so let's start with that.
This is my end goal - it's a simplified version of yours
Data
So let's set out the data that will get us there - in rows. For this example, paste the data into cell A6:
Name Day Time In Time Out Total
Name 1 09/01/17 08:00 18:00 10:00
Name 1 12/01/17 11:00 15:00 04:00
Name 1 13/01/17 12:00 21:00 09:00
Name 2 10/01/17 08:00 13:00 05:00
Name 2 11/01/17 12:00 20:00 08:00
Name 2 13/01/17 10:00 14:00 04:00
And then add another few columns onto the end which will be useful in getting totals and making the table more readable
Unique ID is created simply by concatenating name and day : =A7&B7. And the Time String uses the TEXT function
=UPPER(TEXT(C7,"hAM/PM")&"/"&TEXT(D7,"hAM/PM"))
Table
Create your table in A1:F3 (like below). No need for manual shift data but do put your people and dates headings in:
Use this simple formula in cell B2 and drag down and across to populate shift data
=IFERROR(VLOOKUP($A2&B$1,$F$6:$G$12,2,0),"OFF")
Similarly, you can use this formula for the total hours
=SUMIF($A$7:$A$12,$A2,$E$7:$E$12)*24
Result
The final result is below, and can be easily manipulated for more people/ dates, etc.
If you have questions about any of these formulas/ techniques -- do ask

Related

How do I get the average number of occurrences of a date for each day of the week in excel?

Let's say I have an excel spreadsheet recording some event that reoccurs often multiple times a day, sometimes not at all in a day. So I record the date and a bunch of other information for the event every time it happens. What I'm trying to find is, the average number of times this event occurs on each day of the week.
list of dates
So I want it to look at each day of the week, and find the average number of dates matching each day of the week, starting at the first date and ending at the last date. It should also take into account missing dates, so if there's a Friday with no records, that should affect the average occurrences for Friday.
I've tried using a Pivot Table to find this, and it can get me most of the way there, but it doesn't know to include missing dates within the "count of date" column.
pivot table
I'm not trying to find the average of some other value per day of the week, just the average occurrences of a date per the day of the week. Is this something that is possible in excel, or will I need to use scripts?
For an example where there's multiple weeks of data, I would expect to get a table of results like this:
Day of the week
Average
Mon
2.50
Tue
2.00
Wed
2.50
Thu
2.50
Fri
1.00
Sat
2.50
Sun
2.50
With Friday being lower as there is no Friday date in the provided range (the first Friday has 2 records, and the second Friday has 0 records).
We would need more data to really verify it (try it and let me know). You can use the following formula in cell D1:
=LET(A, A1:A14, B, B1:B14, wdays, TEXT(SEQUENCE(7), "ddd"),
cnts, COUNTIFS(B, wdays, A, TOROW(UNIQUE(A))),
ones, SEQUENCE(COLUMNS(cnts),,1,0), totals, MMULT(N(cnts>0), ones),
sum, MMULT(cnts, ones), HSTACK(wdays, IFERROR(sum/totals,"")))
Or you can use a more succinct formula via BYROW as follows:
=LET(A, A1:A14, B, B1:B14, wdays, TEXT(SEQUENCE(7), "ddd"),
cnts, COUNTIFS(B, wdays, A, TOROW(UNIQUE(A))),
HSTACK(wdays, BYROW(cnts, LAMBDA(x, IFERROR(AVERAGE(IF(x=0,"", x)),"")))))
Here is the output:
Note: If you want the result presented starting from Monday, then define wdays as follow: TEXT(SEQUENCE(7,,2),"ddd").
The name cnts, has the counts per week days (rows) and per columns (unique dates from column A). The rest is just to do the match to calculate the average. We ignore dates with no counts for calculating the average, as per my understanding of the sample input data from the question.

How to create a statement to count total of date and time

I have data in two separate columns like this
But how can I count how many rows are occurring within say a window of 6 AM to 10 PM and outside a window of 10:01 PM to 5:59 AM?
The first column cells are formatted as General. The second column cells are custom h:mm:ss
Fuller View
Here I have a formula to count how many times "Mon" comes up in the left column
=COUNTIF($D:$D,"*"&$K5&"*")
And this is what I have when I try to combine the two to determine how many "Mon" entries were between 06:00 AM and 10:30 PM
=COUNTIFS($D:$D,"*"&$K5&"*",$E:$E,SUMPRODUCT((E2:E119>=M4)*(E2:E119<N4)))
but I get a fat 'ol zero
Yet if I run
=SUMPRODUCT((E2:E119>=M4)*(E2:E119<N4))
I get 116 as a return for the amount of times that a cell is between 06:00 AM and 10:30 PM
So BLUF - I want to count how many times a row has "Mon" and a corresponding time between 06:00 AM and 10:30 PM then I can replicate it for the rest of the days of the week.
New update-dtd 10/11/2022
Right now I know that there are 4 instances where Tuesday had after-hours calls:
Instance one was at 5:59 AM on the 11th
Instance two was at 5:57 AM on the 11th
Instance three was at 10:39 PM on the 11th
& Instance four was at 10:36 PM on the 11th
but with the formula of =COUNTIFS($D:$D,""&$K7&"",$E:$E,">="&$O$5,$E:$E,">"&$P$5)
I am only accounting for 2 of those instances - the 10:39 PM and the 10:36 PM instance (found this out by testing/removing the values in the cells to see what changed the total).
How would I capture the times that are between midnight and 05:59 AM, to include 5:59 AM?
#ScottCraner solved this with
=COUNTIFS($D:$D,""&$K5&"",$E:$E,">="&M4,$E:$E,"<"&N4)

Count for every 'x' that falls into an interval within a given time range?

I'm looking to get a headcount of people available every hour within a time frame.
Employee
Start Time
End Time
Emp name
8:30 AM
10:30 AM
Emp name
8:30 AM
10:45 AM
Emp name
8:00 AM
10:15 AM
If I were to take a count of employees available at 9:45 AM, I should get 3. Or maybe I want 15 minute intervals and want to know my headcount at 8:15, which would be 1.
Currently my solution is to make a table for every hour in a day using the following formula to add a tally for every hour an employee is available:
=IF(AND($G9>=R$1,$G9<S$1),1,IF(AND(R$1>$G9,R$1<$H9),1,""))
And i get something that looks like this:
Start Time
End Time
8:00 AM
9:00 AM
10:00 AM
11:00 AM
8:30 AM
10:30 AM
1
1
Finally I can pivot this or countif it to get my total.
Is there a more elegant solution to this? Preferably one that allows me to change the interval but still gives me an accurate count. Even better if I don't need to build out the interval table.
I'm open to using VBA or formulas.
Overall, what is this problem called? I'd like to look up a pythonic solution on my own time for some self study.
If every line represents a different employee, then just use COUNTIFS:
=COUNTIFS(B:B,"<="&E2,C:C,">="&E2)

Excel - Placing values that fall within a certain time range

I have the following data on duration of particular services.
A B C D
Usage Start (Local time) Start Time Usage Until (Local time) End Time
03.03.2018 10:00 12:00:00 AM 03.03.2018 00:00 1:00:00 AM
03.03.2018 00:00 1:00:00 AM 03.03.2018 00:00 2:00:00 AM
03.03.2018 16:30 1:00:00 AM 03.03.2018 00:00 3:00:00 AM
And I want to count the number of times a timing falls within a certain range(eg. 00:00 - 01:00)
Start End Counts
00:00 01:00 1
01:00 02:00 2
02:00 03:00 1
03:00 04:00
04:00 05:00
05:00 06:00
What formula should I use and how do I apply it?
I have tried this
=COUNTIFS($B$2:$B$566,">="&A2,$D$2:$D$566,"<"&B2)
And this
=SUMPRODUCT(($B$2:$B$566>= A2)*($D$2:$D$566< B2))
But it doesn't account for more than 24 hour duration (Eg.3/3/2018 1:00 PM - 4/3/2018 2:00 PM, 25 hours)
It looks like you're ignoring the time portion in Columns A and C. Assuming your start/end hour bins are in columns F and G, the formula below will give you the number of times that an event passed through your first hour bin (you have to enter it as an array formula--ctrl+shift+enter). Fill down for subsequent hour bins.
=SUM(($B$2:$B$4<F2+TIME(0,30,0))+($D$2:$D$4>F2+TIME(0,30,0))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
This will count an event in an hour bin if the event is active at the half-hour mark.
If the event needs to cover the entire time bin, use this formula (again with ctrl+shift+enter):
=SUM(($B$2:$B$4<=F2)+IF(G2>F2,($D$2:$D$4>=G2))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
Was a bit more complicated than I expected, but I got it to work.
Though before we start, you need to format your table a little. You
can't have date and time in the same cell (as excel has trouble
recognizing storing two formats in 1 cell).
Instead format your table
like so:
Next we should create some hidden rows (technically you can stick what I'm about to do in 1 giant formula, but for sake of clarity I prefer hidden rows)
First we focus on the time difference in hours. Creating the two following columns
Also, make sure, you set the format in these newly added rows to
number. Technically it will work without it, but it will look
confusing to human eye
In the Time defference we use the following formula
=ABS(F2-C2) * 24
In the overnight h column:
=IF(C2>F2, 24-G2, G2) This is utilized that we properly count with transition dates (eg. 23:00 1/1/18 -> 01:00 2/1/18) we don't want to add the extra 24 hours in this case.
That would be the hours fully working, but we also need to ensure the
formula works, when there's more than one night of difference (eg.
1/1/18 -> 3/1/18)
Next, we add these these two rows
In the date difference column, as the column name suggests
=DATEDIF(A2, D2, "d") * 24
Last but not least, the overnight delta is basically the same principle as overnight h, but with dates instead of hours
So now, if we have hidden the rows, added the following formula to result =H2+I2-J2 we get our sought after table:
Which corresponds with the expected result! :)
EDIT: If you don't want to take hours into cosnideration and only count how many times an interval of 24 hours has expired use the following formula
=IF(C2>F2, DATEDIF(A2, D2, "d")-1, DATEDIF(A2, D2, "d"))
(under presumption c2,f2,a2,d2 are in the columns as in my original table i provided)

Specific overtime calculation

I'm working on a simple timesheet that should calculate overtime1 and overtime2, I just cant figure out a good way to fix it.
Normal workday on 8hrs from 07:00 to 17:00 give no overtime (eg 07:00 to 16:00 or 08:00 to 17:00), but when time exceeds 8 hours I would like to get the exceeding hours in a cell.
My business rules are:
1) Any work greater than 8 hours between the hours of 06:00 to 20:00 get paid as overtime1.
2) Any work less than 8 hours will not generate any overtime2 even if after 20:00
3) Any work performed earlier than 06:00 or later than 20:00 get paid at the overtime2 rate.
Example 1: Working from 07:00 to 18:00 would get a value of 3 hours of overtime1
Example 2: Working from 14:00 to 22:00 would generate 0 hours of overtime2.
Example 3: Working 05:00 to 21:00 would give overtime1 6 hours and overtime2 2 hours (1 hour before 06:00, 1 hour after 20:00).
This is a pretty easy problem to solve if your data is laid out smartly. With column A as clock in time and column B as clock out time, use this formula as a helper to determine if you should use the clock in time or your base of 06:00:
=IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))
Then use this formula to determine if you should use clock out time or 20:00:
=IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))
Then you subtract the two to get fractions of a day, multiply by 24 to convert to hours, then subtract 8 to get hours of overtime1. Combined in a super formula it looks like this in C1:
OT1: =IF(OR(ISBLANK(A1),ISBLANK(B1)),"",(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))-IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2)))*24-8)
Remember, Excel formats dates where 1 = 24 hours. Also, I added in an OR(ISBLANK(A1),ISBLANK(B1)) statement to make sure you get a null string if one of the values is blank.
Starting on the overtime2, you need to split it into two parts: before 06:00 and after 20:00. The first part checks if the clock in time is earlier than 06:00 and if so figures out how many hours. The formula ultimately ends up being:
=IF(IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))<=6/24,(6/24-(A1-FLOOR(A1,2)))*24,0)
For after 20:00, the same pattern is used. Figure out how many parts of a day were logged after 20:00. The final formula ends up being:
=IF(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))>=20/24,((B1-FLOOR(B1,2))-20/24)*24,0)
Finally, to figure out the total number of overtime 2, just add the two formulas together in D1:
OT2: =IF(OR(ISBLANK(A1),ISBLANK(B1)),"",IF(IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))<=6/24,(6/24-(A1-FLOOR(A1,2)))*24,0)+IF(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))>=20/24,((B1-FLOOR(B1,2))-20/24)*24,0))
It's just about getting the logic right and understanding that Excel treats 07:00 as a decimal equal to 7/24, for example.
OT1
=IF(NOT(AND(Sheet1!$A2>=7/24,Sheet1!$B2<=17/24)),MIN(20/24,Sheet1!$B2)-Sheet1!$A2-9/24,0)
OT2
=IF(MIN(20/24,Sheet1!$B2)-Sheet1!$A2-9/24,MAX(B2-20/24,0),0)

Resources