Find min and max values in Range - excel

I need to prepare the student attendance sheet from zoom meeting data file. My data is something like this
Name (Original Name)
roll no.
Join Time
Leave Time
Duration (Minutes)
002-Haseebuddin Shakir
002
22/01/2021 03:42:49 PM
22/01/2021 03:46:34 PM
4
002-Haseebuddin Shakir
002
22/01/2021 03:50:49 PM
22/01/2021 05:31:34 PM
100
003_Abdul Wasay
003
22/01/2021 03:53:51 PM
22/01/2021 04:31:30 PM
98
003_Abdul Wasay
003
22/01/2021 04:35:51 PM
22/01/2021 05:00:30 PM
60
003_Abdul Wasay
003
22/01/2021 05:01:51 PM
22/01/2021 05:31:30 PM
20
004_Ismail (04_Ismail)
004
22/01/2021 03:47:44 PM
22/01/2021 05:31:31 PM
104
005 saud
005
22/01/2021 03:51:07 PM
22/01/2021 05:31:43 PM
101
006-Akber (Akber-006)
006
22/01/2021 03:41:12 PM
22/01/2021 05:05:43 PM
85
I need help to find the 1st joined time, last left time and total of minutes. for understanding purpose used random figures.
I have tried thru pivot table but getting date 1900 whenever I use min/max and even tried aggregate function but I am not that perfect using aggregate.
Looking for output
Name
Roll no
Join time
Last leave time
total no. min's
002-Haseebuddin Shakir
002
22/01/2021 03:42:49 PM
22/01/2021 05:31:34 PM
104
003_Abdul Wasay
003
22/01/2021 03:53:51 PM
22/01/2021 05:00:30 PM
178

I propose a powerquery/powerpivot solution like this -
remove auto filter
select data
from table on get&transform group on Data tab
it will look like this
select name and rollnum both, rightclick group-by. add aggregations like the screenshot
close and load the data back (it will automatically load to a new sheet in same book)
Note I think you'll these aggregations for each of the day for each of the roll number. It is therefore, advised that create a separate column of date before loading the data into powerquery window and thereafter groupby on name rollnum and date columns.

Related

Wonderware History Tags

When I run my function to retrieve the history values in Wondereware into Excel it only loads 4 of the 50 tags.
I have tried to select the cells that have the tag names in it and it seems that it only takes 4 of the tag names and I need all 50.
=wwWideHistory3("LEWC2012INSQL", AFTagBinding,"Row7",AFStartBinding,AFEndBinding,254,0,0,0,0,3,0,"",3,"",-1,0,"","NoFilter",16384)
The 4 tags that it loads. I need 50 tags.
DateTime L2_PT6130 L2_PT6230 NU_DC01_DX01_DISPLAY NU_DC01_DX02_DISPLAY
6/1/19 6:00:00 AM 2.255943775 3.29255867 0.039721143 -0.231841758
6/2/19 10:00:00 AM 2.26124382 3.646864653 0.084306099 -0.209954605
6/3/19 2:00:00 PM 2.498756409 3.312580585 0.042153049 -0.206712067
6/4/19 6:00:00 PM 2.703880787 3.238382339 0.027561609 -0.233463034
6/5/19 10:00:00 PM 2.20412302 3.113344669 0.091601819 -0.229409859
6/7/19 2:00:00 AM 2.044145584 2.985558987 2.3581388 0.968709469
6/8/19 6:00:00 AM 2.187830925 3.223267794 2.323281527 0.663099885

Pandas strftime with 24 hour format

QUESTION
How can I convert 24 hour time to 12 hour time, when the time provided is two characters long? For example: How to format 45 as 12:45 AM.
ATTEMPT
I can get most of the time conversions to format properly with the following:
df=df.assign(newtime=pd.to_datetime(df['Time Occurred'], format='%H%M').dt.strftime("%I:%M %p"))
df.head()
Date Reported Date Occurred Time Occurred newtime
9/13/2010 9/12/2010 45 4:05 AM
8/9/2010 8/9/2010 1515 3:15 PM
1/8/2010 1/7/2010 2005 8:05 PM
1/9/2010 1/6/2010 2100 9:00 PM
1/15/2010 1/15/2010 245 2:45 AM
In the above the values in newtime are properly formatted, except where in the input time is "45" - that time had the result 4:05 AM. Does anyone know how to create the proper output?
to_datetime
times = pd.to_datetime([
f'{h:02d}:{m:02d}:00' for h, m in zip(*df['Time Occurred'].astype(int).__divmod__(100))
])
df.assign(newtime=times.strftime('%I:%M %p'))
Time Occurred newtime
0 45 12:45 AM
1 1515 03:15 PM
2 2005 08:05 PM
3 2100 09:00 PM
4 245 02:45 AM

How do I find a list of available timeslots given scheduled dates from list in Excel/VBA sheet?

I have a list of scheduled appointments already and want to be able to show all possible timeslots available between 7:30 AM - 5:00 PM for a 2 hour appointment. I've tried a visual and been able to get it through a hack, but I need to get it to work just from reading the below table
SCHEDULED APPOINTMENTS
|---------------------|-------------------|
| Start Date/Time | End Date/Time |
| 6/12/2019 7:30 AM | 6/12/2019 8:30 AM |
| 6/12/2019 8:45 AM | 6/12/2019 9:15 AM |
| 6/12/2019 3:00 PM | 6/12/2019 3:30 PM |
| 6/12/2019 3:45 PM | 6/12/2019 4:15 PM |
| 6/12/2019 4:15 PM | 6/12/2019 5:00 PM |
|---------------------|-------------------|
EXPECTED OUTCOME:
6/12/2019 9:15 AM
6/12/2019 9:30 AM
6/12/2019 9:45 AM
6/12/2019 10:00 AM
6/12/2019 10:15 AM
6/12/2019 10:30 AM
6/12/2019 10:45 AM
6/12/2019 11:00 AM
6/12/2019 11:15 AM
6/12/2019 11:30 AM
6/12/2019 11:45 AM
6/12/2019 12:00 PM
6/12/2019 12:15 PM
6/12/2019 12:30 PM
6/12/2019 12:45 PM
6/12/2019 1:00 PM
To get just that list directly would require VBA, which is possible, but StackOverflow is not a write-your-code-for you service. We would help if you got stuck with your code, but you need to know how to code in the first place and have made a start.
That said, if you accept a slightly easier solution, then a single formula can give you your desired result:
Convert your appointments range to a data table with column headings "Start" and "End"
Set the table name to "Appointments"
Store your new appointment length (2) in a cell and give it the name "Length"
Create a list of every possible appointment start time, starting from A1
Enter this formula next to the first time in B1, and save it by pressing CTRL+SHIFT+ENTER:
=AND((ROUND(Appointments[Start],4)>=ROUND(A1+Length/24,4))+(ROUND(Appointments[End],4)<=ROUND(A1,4)),ROUND(A1-TRUNC(A1),4)<=ROUND((17-Length)/24,4))
Then fill down that formula against every time slot and it will say TRUE for the available time slots.
For each possible time slot, the formula checks that all existing appointments finish on or before the time slot or start 2 or more hours after the time slot. It also checks that there are at least 2 hours left in the day before finishing at 5pm. The formula handles different lengths required for the new appointment by changing the value in the "length" cell.
The ROUND functions are added to eliminate issues with floating point precision on fractions/times not always correctly identifying when 2 times are the same.

Convert incomplete 12h datetime-like strings into appropriate datetime type

I've got a pandas Series containing datetime-like strings with 12h format, but without the am/pm abbreviations. It covers an entire month of data :
40 01/01/2017 11:51:00
41 01/01/2017 11:51:05
42 01/01/2017 11:55:05
43 01/01/2017 11:55:10
44 01/01/2017 11:59:30
45 01/01/2017 11:59:35
46 02/01/2017 12:00:05
47 02/01/2017 12:00:10
48 02/01/2017 12:13:20
49 02/01/2017 12:13:25
50 02/01/2017 12:24:50
51 02/01/2017 12:24:55
52 02/01/2017 12:33:30
Name: TS, dtype: object
(318621,) # shape
My goal is to convert it to datetime format, so as to obtain the appropriate unix timestamps values, and make comparisions/arithmetics with other datetime data with, this time, 24h format. So I already tried this :
pd.to_datetime(df.TS, format = '%d/%m/%Y %I:%M:%S') # %I for 12h format
Which outputs me :
64 2017-01-02 00:46:50
65 2017-01-02 00:46:55
66 2017-01-02 01:01:00
67 2017-01-02 01:01:05
68 2017-01-02 01:05:00
But the am/pm informations are not taken into account. I know that, as a rule, the am/pm first have to be specified in the strings, then one can use dt.dt.strptime() or pd.to_datetime() to parse them with the %p indicator.
So I wanted to know if there's an other way to deal with this issue through datetime or pandas datetime modules ? Or, do I have to manualy add the abbreviations 'am/pm' before the parsing ?
You have data in 5 second intervals throughout multiple days. The desired end format is like this (with AM/PM column we need to add, because Pandas cannot possibly guess, since it looks at one value at a time):
31/12/2016 11:59:55 PM
01/01/2017 12:00:00 AM
01/01/2017 12:00:05 AM
01/01/2017 11:59:55 AM
01/01/2017 12:00:00 PM
01/01/2017 12:59:55 PM
01/01/2017 01:00:00 PM
01/01/2017 01:00:05 PM
01/01/2017 11:59:55 PM
02/01/2017 12:00:00 AM
First, we can parse the whole thing without AM/PM info, as you already showed:
ts = pd.to_datetime(df.TS, format = '%d/%m/%Y %I:%M:%S')
We have a small problem: 12:00:00 is parsed as noon, not midnight. Let's normalize that:
ts[ts.dt.hour == 12] -= pd.Timedelta(12, 'h')
Now we have times from 00:00:00 to 11:59:55, twice per day.
Next, note that the transitions are always at 00:00:00. We can easily detect these, as well as the first instance of each date:
twelve = ts.dt.time == datetime.time(0,0,0)
newdate = ts.dt.date.diff() > pd.Timedelta(0)
midnight = twelve & newdate
noon = twelve & ~newdate
Next, build an offset series, which should be easy to inspect for correctness:
offset = pd.Series(np.nan, ts.index, dtype='timedelta64[ns]')
offset[midnight] = pd.Timedelta(0)
offset[noon] = pd.Timedelta(12, 'h')
offset.fillna(method='ffill', inplace=True)
And finally:
ts += offset

Finding out total worked hours and minutes formula

FROM TO FROM TO FROM TO
7:30 AM 2:00 PM 2:40 PM 2:40 PM 6:30 PM 12:00 AM
7:30 AM 2:00 PM 2:40 PM 2:40 PM 6:30 PM 12:00 AM
7:30 AM 2:00 PM 2:40 PM 2:40 PM 6:30 PM 12:00 AM
HOUR(H2-C2)& "h"&MINUTE(H2-C2)&"m")
HOUR(F2-E2)&"h")
Can you check what is the error in this formula:
(HOUR(H2-C2)& "h"&MINUTE(H2-C2)&"m")-(HOUR(F2-E2)&"h"& MINUTE(F2-E2)&"M")
I want the total hours worked by each person in this format: 12h48m
Don't you need the time between C2 and D2 added to the time between G2 and H2, that's what it looks like from your screenshot? You can also add in the difference between E2 and F2 if that's likely to be non-zero
You can use MOD function to handle times passing/on midnight, e.g.
=MOD(D2-C2,1)+MOD(H2-G2,1)+MOD(F2-E2,1)
Custom format result cell as [h]:mm and you'll get 12:00, I'm not sure why it would be 12:48. If you actually want it to display as 12h00m then use a custom format for the result cell of
[h]"h"mm"m"

Resources