How to create a statement to count total of date and time - excel-formula

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)

Related

Excel Plotting two Date Ranges on the same Pivot Table

I am trying to trend the occurrence of a system event in Excel. I've attached a screen shot showing the pretty simple data that I'm working with.
The spreadsheet lists the times of the event (Column A) for a two week period and I've used a ceiling formula to group those events into 15 minute increments (Column B). Using a pivot table and chart, it's pretty simple to then take that data and graph the events into a line chart that shows the 15 minute increment time, and the count of the events in that 15 minute period.
Now I'd like to take subsets of that data and compare them. For example I'd like to compare Friday Saturday Sunday of last week Friday Saturday and Sunday of this week. So far, the only way I found to achieve this is to create duplicate pivot tables (Columns E, F and H,I), filter each table by the days I want to compare (25, 26, and 27 in one table and 1, 2 and 3 in the second), and then visually compare them (the Two charts).
But what I'd really like to do is to combine both series into one chart as a stacked line graph. I thought that would be pretty simple, but since the dates are so very dissimilar, I always wind up getting a single line or duplicate data, or totally off the wall results.
I've gotten kinda close by converting the row labels in to a custom DDD HH:MM format. That lists the Dates as (For Oct 25th)
Fri 00:15 11
Fri 00:30 1
Fri 00:45 4
Fri 01:00 3
Fri 01:15 6
Etc.
And (For Nov 1st)
Fri 00:15 7
Fri 00:30 1
Fri 00:45 2
Fri 01:00 1
Fri 01:30 2
Etc
Now I have something I can join on (Friday 00:15, 00:30, 00:45, etc is in both charts)
But the problem is, the two series often don't have the same Labels. For example the data for Nov 1 is missing 01:15,01:45 and 02:00 because no events occurred at those times. Same problem for the Oct 25th's data which is also missing 02:00 in addition to all increments between 02:30 and 03:45.
I tried just manually inserting the missing times in both charts but that quickly became a very complex and error prone chore.
So the question is: Is there a way to get excel to automatically fill in the missing time slots or am I completely off base in the way I'm trying to do this?
OK.. that was two questions :)
Thanks so much for your help!

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)

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

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

Excel: auto format time of day when inputting time

I'm inputting time in and time out logs for my business to calculate the total hours worked by individual contractor companies visiting my site. We operate from 6:30am to 5pm. Excel automatically formats the data as AM, except for 12:00-12:59 which it correctly assumes is PM. I need excel to recognize that any time between 12:00 and 5:00 is PM. This will save me from having to type PM for each "time out" which over the course of a year will save me hours.
I'm not really sure how to do this. I'm guessing an if/then macro?
You can change the cell format as shown below:
when you type 17:00 is correctly displayed as 5:00 PM
I just use military time to get around this problem. 5 PM is not 5:00, but rather 17:00. Then you don't need to put in a PM or anything. Note: This is just for inputting the time. You can still display the time as 5:00 PM or whatever by formatting those cells or columns as the 'Time' type.
1 PM = 13:00
2 PM = 14:00
3 PM = 15:00
4 PM = 16:00
5 PM = 17:00
6 PM = 18:00
etc.

Resources