Find earliest entry in a table - excel

Consider the following table of employees.
It's fairly simple right? Clock in when you start, clock out for lunch, clock back in after lunch, clock out when you leave. But can someone please tell me what time these employees actually started? So for example how would you go about saying Tom was here at 6:51 AM and not at 12:23 PM?
For more reference, all entries look like this. They have at least 4 entries, (some one, no lunch).
How do I go about writing a formula that returns the start time?
I edited the table and added a helper column for the date. See below.
ANSWER:
=AGGREGATE(15,6, $C$2:$C$7/((A11=$A$2:$A$7)*(B11=$B$2:$B$7)),1)

If the working hours are within the day, you can search for the smallest time. If there is a night shift over midnight, then there is a problem ...
=AGGREGATE(15,6,(1/($A$2:$A$5=A2)*(INT(B2)=INT($B$2:$B$5)))*($B$2:$B$5),1)

I've written down this formula for range E2:
=IF(AND(A2=A3,TRUNC(B2,0)-TRUNC(B3,0)=0),MIN(B2,B3),IF(AND(IFERROR(TRUNC(B2)-TRUNC(B1)=0,FALSE),E1=MIN(B2,B1)),"",B2))"
Since english is not my default language on Excel, i've just manually translated it. Anyway, just in case, here is the VBA code to paste it in range E2:
Range("E2").FormulaR1C1 = "=IF(AND(RC[-4]=R[1]C[-4],TRUNC(RC[-3],0)-TRUNC(R[1]C[-3],0)=0),MIN(RC[-3],R[1]C[-3]),IF(AND(IFERROR(TRUNC(RC[-3])-TRUNC(R[-1]C[-3])=0,FALSE),R[-1]C=MIN(RC[-3],R[-1]C[-3])),"""",RC[-3]))"
I've tried various configurations and it works for me. Only point: list must be sorted by Name and Clock In.

Related

Caclulate if Now() is between 2 times across midnight Excel

I feel a bit noob asking this but been scratching my head trying to figure out a solution for this problem. (ADHD hitting hard as well)
I have a list of people that are schedule to work in various time segments, some of them with shifts that crosses midnight, and after comparing it with a different data set know if the person if the person is working or not.
Column A contains the list of people,
Column B and C contains the days off, combined with + =Today()
Column D contains the time when the shift begins, (As it time only, added =Today)
Column E contains the time when the shift ends,
Column F will indicate if that specific person is in their day off or they need to work, used the following code for it
=IF(OR(B3=(TEXT(TODAY(),"ddd")),C3=(TEXT(TODAY(),"ddd"))),"Week-Off","Workday")
In column G I want to know if the person is working or they are absent after matching it with another table using this formula
=IF(F2="Workday",IF(AND(Now()>=$E2,(Now()<=$F2),"Scheduled","Off-Shift")," ")
So far the code has worked for everyone who has schedules that ends at 11:59 pm, but when the shift ends at midnight or it crosses midnight it provides incorrect results (Shows Offshift instead of Scheduled)
In Short I want to know if =Now() is between 2 times, when is in the same day or the shift crosses midnight.
Code (Asume Now() is 1:30 am)
=IF(F4="Workday",IF(AND(Now()>=$D4,(Now()<=$E4),"Scheduled","Off-Shift")," ")
Expected Result
Schedule
Actual Result
Off-Shift
As on now i feel is a pretty easy solution but unable to wrap around a solution, and somehow my brain is focus on using IF. As an extra bonus if it can be done by Excel-VBA it will be a plus
After looking a bit further found the solution in the following post: Determine if a given time is between start and end time

Need proper formula to obtain correct value

It's my first question here. I need a formula which take the correct code at specific date. After taking correct code, excel table is using it for calculation of the correct value.
The concept is a little complicated. There is a calendar which is starting at 15.09.2021 (V3 Cell) and ending at 04.06.2022(JX3 Cell). And our codes are: ITB, OR, TBE, CBE, PO, VDR, SMF, FMF and DS. All of them are the steps of procurement process. And each of them has a specific values/coefficients like 0.1, 0.2, 0.15 etc and everyone comes true at specific date. And their locations are L2 to T2.
For example, we are taking the codes for procurement of generator at 15 September 2021:
=IF(V$3=$L5;$L$2;IF(V$3=$M5;$M$2;IF(V$3=$N5;$N$2;IF(V$3=$O5;$O$2;IF(V$3=$P5;$P$2;IF(V$3=$T5;$T$2;IF(V$3=$S5;$S$2;IF(V$3=$R5;$R$2;IF(V$3=$Q5;$Q$2;0)))))))))
L5 to T5 are the dates of procurement steps of that item.
And we are using same formula for other dates. It is working. But when, for example TBE and CBE completed at the same day, excel takes one of them (which is first). Sometimes 4-5 steps are completing at the same day. And for this situation, we can not take the true value of the item's procurement. We are calculating the progress of the procurement in that way. But as I said, it isn't working for the same dates. I tried to fix the formula by putting all possible combinations and giving them new code and coeffient:
=IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=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R5;$R$2;IF(V$3=$Q5;$Q$2;0))))))))))))))))))))))))))))
New codes are at U117 to u152.
As it can be seen, it is so rough method to use. I tried to put every possible combination but also there is a character limit and i can't write all of them too.
I hope I could explain the problem well. Maybe it can be solved by VBA too.
I'll be glad if anyone helps for practical methods. Thanks.

Check range of times in excel to ensure they are within core hours

I am trying to check to see if the following Times in the picture fall within a certain core hour of 0930 - 1430, in military time. This breaks because you aren't clocked in at 930 therefore missed a half an hour of core time.
Currently I am using min/max to check for those columns which works until this example. Any ideas would be great!
Here is an example:
Here is what the output should look like (even though the math is wrong.
It should say CR Missed=1.5 (Core Hour starts at 930 and clock in was 11).
The current code I am using
=IF(AND(COUNTA(J8:J12)<>0,COUNTA(K8:K12)<>0),IF(AND($AQ$15>=MIN(J8:J12),$AR$15<=MAX(K8:K12)),"","CR Missed = "),"")
Edit: Sums are not relevant (it just adds the times) AQ=0930 and AR=1430 (The range of "Core Hours")
Essentially you can enter in different times in each row and I am trying to make sure that you are 'logged in' between required times of 0930 and 1430. Currently the Min/Max equation works ish but doesnt cover the shown example where I am actually missing 30 mins (logged out at 0900 and logged back in at 1000).
I feel like I am missing some logic or command. Sorry, I hope this helps.
From Comments and to add clarity, added an example of the ouput
There can be more lines; I have up to 5 (Just hidden)
The times dont have to be in order but generally thats how they would be entered.
No these are technically different time codes (Leave/Sick/Regular) You would not overlap Sick and Leave for example
Solved
I would like to thank everyone for the help!
The function I ended up using was Ron's example with a twist. As his example showed how many hours worked that were within a time range; I wanted to show how many were missing; and since multiple check ins/outs could happen I just covered all the available slots.
=ABS((5-(MAX(MIN(EndTime,K9)-MAX(StartTime,J9),0)*24))-(5-(MAX(MIN(EndTime,K10)-MAX(StartTime,J10),0)*24)))
So this will give me the number of missed hours between required time interval with multiple check in and check outs.
Preface
My approach was to look for the first time-slot that covered the starting time (9:30).
If we find a time-slot like (7:00 - 10:00), we need to check if the next time slot starts at 10:00.
If the next time slot covers 10:00, we will check this time slot's end time with the next one.
And we repeat this process until all time-slots have been checked. If the time we end up with is greater than your "core end time" (14:30), then we know that all hours of the core hours have been covered continuously without breaks (might even be more).
On the contrary, if it is smaller, the value we ended up with, is the last point in time that they worked continuously without any gaps.
Formulas & Explanations
Insert start time into D1, and end time in E1.
In C2 and downwards is: =IF(AND($B2>$D1;$D1>=A2);$B2;$D1)
This is what checks if the time we were looking for was in this interval, if it was, this value will change into the end time of the time slot. If not, it will remain as the previous - this is what lets us know not all core hours have been covered.
D2 and downwards is simply: =MAX(D1;C2) (This could be included in C1, but for readability and to easier understand, I made it a separate column.
Finally E4, whether or not all core hours have been covered is: =C4>=E1, which becomes TRUE or FALSE. If you want the "CR Missed", that will be a simple: =IF(E4;"";"CR Missed")
I realize this isn't very dynamic, so if you have more time slots, you will have to copy the formula down further.
So, maybe this won't be the ultimate solution, but rather do the job and perhaps be enough for you to expand upon.
Best regards! ^_^
It is not clear to me what you want for output. Perhaps this will get you started.
To compute the hours from Start=> End that fall within a certain range (eg: Core Time):
=MAX(MIN(TIME(14,30,0),End)-MAX(TIME(9,30,0),Start),0)
So you could do something like:

How to filter data of last record of each week

I have a big data set of daily selling value of a particular ITEM. I want to know what was the price of ITEM on the last day of each week. Typically the last working day is Friday but if you don't have data for Friday then we need to get the previous working day data (Thursday).
Monday is considered the First day of week.
My Data looks something like this:
Data is in cells A2:C13.
My expected output is shown below:
Please help with VB macro or even simple excel formula.
You may want to try using a formula using the LOOKUP function, to search the list from bottom to top.
Afterward, a combination of INDEX and MATCH may get you on the right path as well.
Edit: I realize now that I was leading you astray because I thought you were asking something else! The most straightforward way I can see is as follows:
use WEEKDAY() to pull out the weekday values (as you did), except leave the values as numbers (with 1 being Sunday and 7 being Saturday).
Check each of these days to see if it precedes (i.e. has a lesser value) than the day above it. If not, we know that the week started over, and that cell is the last day of the week. Therefore, display its value.
Of course, this assumes that there are no Saturdays in your data - otherwise, Saturday would be listed as the end of the week. If you're crafty you can fix this dilemma though!
Thanks, Tyler.
Your suggestion helped me a lot in putting efforts in the right direction.
The way I did is as follows:
First I sorted my data in decreasing order of date so that I can have all the latest data at the top.
Range("AW4:BE999999").Sort Key1:=Range("BC4:BC999999"), order1:=xlDescending, Header:=xlYes
From Date created a string of "YEAR"&"WEEKNUM". This way I was able to group all the days in a specific week. Formula Used is:
=(TEXT(BC5,"yyyy"))&(TEXT(WEEKNUM(BC5),"00"))
Then I gave a unique Number to each record. The best way I could think of is to give the row number where record belongs.
=ROW(AY5)
Now using VLOOKUP function I got all the records matching string I have created in step 2
=VLOOKUP(AZ5,AZ:BD,5,FALSE)
I applied the above formula to get all the columns that I need.
Now I removed all the duplicate rows using below formula:
Cells.RemoveDuplicates Columns:=Array(1)
Now the remaining rows are the expected rows.
There may be a better way to do this but this is my first time with excel macro and formulas, so feeling happy.
Please comment other better ways to do this. It's always good to keep on improving our work.

Calculate minutes in specific period

I have a spreadsheet which has employee working times, listed as Sat-In and Sat-Out for a specific date. The employee shift spans several ours and each "In-Out" period is recorded as a separate line which means the time between the Sat-Out and the next Sat-In means the employee is on a break. I also calculate the time, in minutes of each "sitting" period.
What I can't seem to figure out is how to add a formula which takes the data and further refines it in this manner:
1. I have a core period of 1030-1530, as an example, which is the busy time and requires the maximum employee coverage. The shifts of employees generally spans this core, but in some cases their shift may start or end in the core.
2. I want to calculate how many minutes the employee worked within the core only. I can obviously do this manually using the data, but a formula would be preferred, if possible.
3. As an example, if a person sat-in at 1445 and sat-out at 1545, the core time calculation would be 45 minutes (1445-1530).
I've attached a snapshot of the data to help my explanation.
FYI - the information is pulled from a database as JSON data and converted to excel. I'm not very familiar with JavaScript, but if someone knows a way to do it programatically, I'm willing to give it a try and learn.
Thanks!
![excel]: https://photos.app.goo.gl/dRSTE72CXNa18RzP8
In below example I've used: =MAX(0,MIN($O$2,H2)-MAX($O$1,G2)), and formatted like [mm].
In Excel, units are days, so if you want to calculate the amount of minutes between two timestamps, you need to subtract both and multiply the differencee by 24*60 (being the amount of minutes in one day).
E.g. You start working at 09:07 (cell B2), and finish at 18:07 (cell B3), having a 45-minutes break. Then the time you worked in minutes, is:
=(B3-B2)*24*60-45
Make sure the cell formatting is correct (general), you'll get : 495.

Resources