Compare a time field with a time range to determine the value in Excel - excel

I need column C should check the time in column B and compare it with F and G column and display value from column E
Example : 8:30:01 AM is between 4:30 am and 12:30 pm so it should return shift1 as a output in column C

Use:
=IFERROR(INDEX(E:E,MATCH(B2,F:F)),"shift3")
For those with XLOOKUP:
=XLOOKUP(B2,F:F,E:E,"shift3",-1)

I'm having a hard time getting comparisons to work on the time fields. Can you use military time instead and just use the numbers,e.g. 133001 for 1:30:01 pm? If so the following will work
=IF(AND(B3>$H$1,B3<$I$1),$G$1,IF(AND(B3>$H$2,B3<$I$2),$G$2,$G$3))

Related

Converting Excel Date/Time to 24-hour with missing characters

I received a sheet with thousands of records where the date/time records are incorrect. Some of the time format is missing a leading zero, and I need to trim off the AM/PM and seconds places. Time time needs to be in 24-hour (military) time. Ex:
10/8/2016 80000 AM
Should be: 2016-10-08 08:00 (yyyy-mm-dd hh:mm)
Some of the other records have the correct amount of characters. Ex:
10/8/2016 120000 PM
Should be: 2016-10-08 12:00 (yyyy-mm-dd hh:mm)
Therefore, I can just trim the PM and seconds from the right.
General rule: If the number begins with a 1 it is likely a time between 10:00 and 19:59, if the number begins with a 2 - 9 likely just add a 0 in front and making it 02:00 through 09:59.
My challenge is finding a formula that will accomplish all of this so I don't have to wade through thousands of records to fix the time.
I suspect that you have already figured this out but here is one approach (just because I found it interesting)
So column A holds the actual value
Column C has the following formula to extract the date (presumption here is that first part of the string in column A is a date):
=TEXT(LEFT(A2,FIND(" ", A2, 1)-1), "yyyy-mm-dd")
Column D extracts the time string from column A:
=LEFT(RIGHT(A2,LEN(A2)-SEARCH(" ",A2)),SEARCH(" ", RIGHT(A2,LEN(A2)-SEARCH(" ",A2)))-1)
Now to convert the value in column D to a 24hour time format (without the :) based on AM or PM in column A. So column E is:
=IF(UPPER(RIGHT(TRIM(A2),2))="PM",IF(LEFT(TRIM(D2),1)="1",12+INT(LEFT(D2,2)),12+INT(LEFT(D2,1)))&RIGHT(TRIM(D2),4), D2)
All that is left is to create the required string.. that's where column F comes in:
=C2& " "&IF(LEN(E2)=5,"0"&LEFT(E2,1),LEFT(E2,2))&":"&IF(LEN(E2)=5,MID(E2, 2,2),MID(E2, 3,2))
Not sure if this is the best approach but first one that came to my head :)

How do I calculate this time? Across midnight

I have a sheet with start and end dates and values.
In C I have start date.
In E I have end date.
In I I have start time. (06:05:00)
In J I have end time. (08:33:00)
If C <>E I need to add 24 hours to the time elapsed.
How can I do that?
I tried if(C2<>E2;1+J2-I2;"omitted")
But I get the result 21:32:00.
It should be about 26 hours
(24+8-6 = 26 if we only look at the hours).
What have I done wrong?
Edit;
Back at work and can now upload some images.
Method 1
Method 2
Both return the wrong time.
EDIT2;
Method 3
I remember how I always have to format the dates from "our" format to Excels format for it to be recognized as a date.
In column P I use RIGHT(), MID(), and LEFT() to make a correct formatted date.
In R and S I use the same as P&Q column.
Still not correct.
:-/
EDIT again:
Use formula: =(E1+J1)-(C1+I1) we just add the date and time together and subtract the end from start and then format the cell having the formula to show days, hours, minutes.
This way, if you have more than 1 day difference, you're not just adding 24 hours.
Change the format of the target cell contianing the above formula to
d "days" hh "hours" mm "minutes"
or use the format tigerAvatar suggested of [hh]:mm if you want the hours to be cumulative across days.
Then you get a nice output of: 2 days 02 hours 28 minutes or 50:28
Feel free to drop the 1 h or 1 m if you don't want the leading zeros.
A picture is worth a 1000 words so:
Version 2 after your screenshots: I don't think C, E are in date format based on your updates so...
I used formula=(DATE(LEFT(E2,4),MID(E2,5,2),RIGHT(E2,2))+J2)-(DATE(LEFT(C2,4),MID(C2,5,2),RIGHT(C2,2))+I2) in K and custom format mask: [h]:mm
If this doesn't work it may be a regional setting and the interpretation of [h]:mm I am assuming I/J are time formats.

Excel Formula - get the date of a maximal value within a list

I have a rather big (long) table and need to do something quite simple but I'm currently with a sort of blackout...
Imagine that you have:
Date 1 Value 1 Date 2 Value 2 Date 3 Value 3 Date of MAX
... ... ... ... ... ... ????
I want to deploy in ???? a formula that will result in the date at which the maximal value (between Value 1...3) was registered. For instance:
Date 1 Value 1 Date 2 Value 2 Date 3 Value 3 Date of MAX
20160501 10 20160722 47 20161002 9 20160722
meaning, the Date of MAX is of Date 2 because that was the date at which the MAX was measured.
Thanks in advance.
You could do a more general solution using offset:-
=MAX(N(OFFSET(D2,0,COLUMN(A:D)*3)))
to find the largest value - put this in (say) R2.
Then find a match for it and pick out the corresponding date:-
=OFFSET(C2,0,MATCH(R2,N(OFFSET(D2,0,COLUMN(A:D)*3)),0)*3)
assuming the dates and values are every third column.
These are array formulae and must be entered with CtrlShiftEnter
If the last value really was in P21 you would have to give a row offset as well as a column offset.
OK, I found a dirty but simple solution (don't know why I didn't think of it at first):
=IF(G2>=MAX(G2,J2,M2,P21),F2,IF(J2>=MAX(G2,J2,M2,P21),I2,IF(M2>=MAX(G2,J2,M2,P21),L2,O2)))
where the pairs (4 of them) are at FG, IJ, LM, OP. Not elegant but does the job.

Computing Average In MM:SS in excel

Input: Minutes:Seconds
Output: Average in Minutes:Seconds
I currently have a sheet where we put in handle times for calls. We want to compute the average handling time in minutes:seconds. Now, currently we have minutes in Column A and seconds in Column B. In Column C, I convert A&B to total seconds. In Column D, I use =AVERAGE(C1:C6) to compute for average.
Question: Do we have an easier way to doit? Specifically, is there any formula that will allow me to simply input Minutes:Seconds in a single column and have the average in Minutes:Seconds to be calculated?
Option 1:
(If you can change your input format):
You need to set the data format as hh:mm:ss
Inputting the data in this format will allow excel to automatically detect the format and as such, allow for you to use the 'average' formula.
For example, if you have 3 entries for: 2 minutes, 1 min 30 secs and 1 minute, the data in col A should look like:
00:02:00
00:01:30
00:01:00
You can then run, for example, the formula:
=AVERAGE(A1:A3)
Note: By default, putting the data in the format "xx:yy", excel will assume that xx is the hours and yy is the minutes, so you should pass the initial 00: if you don't have your time in hours
Option 2:
(If you cannot change your input format):
If you need to stick to the format where col A contains the minutes and col b contains the seconds, you can use the following formula to pass "hh:mm:ss" data in col c:
=(A1/(24*60))+(B1/(24*60*60))
(default date value is set to '1 day' for a cell, so we divide by 24 hrs and 60 mins to convert it to 'minutes' from col A and 24*60*60 to get seconds from col B)
You can then use a folmula similar to the one below to calculate the average time in col C:
=AVERAGE(C1:C3)
Note: You would need to set column C to the 'Custom format':
hh:mm:ss

Data Chart to show times of day in Excel

I have a data set where by i am required to show the sum of calls for a date and their call times also.
Here is an example of my data set for a few days for one extension
6/24/11 7:43:38 AM
6/24/11 8:10:23 AM
6/24/11 8:16:54 AM
6/24/11 8:20:45 AM
6/24/11 4:47:06 PM
6/25/11 12:38:43 PM
6/25/11 5:38:10 PM
6/26/11 7:32:53 AM
6/27/11 5:40:32 PM
6/28/11 3:46:05 PM
6/29/11 7:09:21 PM
6/30/11 5:59:54 AM
6/30/11 1:21:28 PM
6/30/11 5:59:00 PM
Is it possible to put this into a chart whereby we can see a sum of calls for a given date? If that makes sense.
Thanks,c
-=
I found the following post at Excel Timesheet
this fixed my problem.
Easiest way is to have a number of helper columns:
Example:
Column A through C contain the raw data for Extension 1-3
Column D through E contain the 'truncated' version of the time stamp into days
Column H through K would contain the frequency of calls for a given day and extension
Put the formula in E in order to get the truncated day, and expand it over the columns E-G
=DATE(YEAR(A3),MONTH(A3),DAY(A3))
Put the starting day of interest in Cell I2. For Cell I3 enter the formula
=I3+1
so you will have automatically incrementing days in that column, this is your 'bin' for the histogram you're about to make.
Count the number of times the value in E is found for a day in your bin
In J ( column counting calls per day for extension 1 ) enter the formula:
=COUNTIF(E$3:E$16,$I3)
drag this formula out.
Now you should have the data for your histogram/plot in columns I through L.
I found the following post at Excel Timesheet
this fixed my problem.
Excel Timesheet

Resources