Excel convert range of dates into time to find whether it is greater or less than timeframe - excel-formula

I have the below formula doing a count of what rows have a time greater than 3:00pm OR a time less than 4:00am. It works as expected if my rows E1:E5 are only times. However the issue is that column E is a date time and I would like to keep it that way. So the formula currently is returning 0.
Formula
=COUNTIF(E1:E5,">="&TIME(15,0,0)) + COUNTIF(E1:E5,"<="&TIME(4,0,0))
Column E
10/1/2018 2:40:58 AM
10/1/2018 2:11:58 AM
10/1/2018 2:09:50 AM
10/1/2018 9:41:53 AM
10/1/2018 9:22:21 AM
The formula should return the count of 3. Thanks for any help.!

If you're okay with a helper column (which you can hide all the way in the AA column if you desire), you could do something like this:
If you decided to go with column AA, then in AA1, type:
=MOD($E1, 1)
and fill down. Any real number can be divided by itself, so MOD will just return the remainder - which would be the fractional number that represents the time.
Your COUNTIF() formula will then look like:
=COUNTIF($AA1:$AA5,">="&TIME(15,0,0)) + COUNTIF($AA1:$AA5,"<="&TIME(4,0,0))

Inspired by some of the suggestions I came up with the following:
=SUMPRODUCT(
((A2:A17-TRUNC(A2:A17))>=0.625)*
((A2:A17-TRUNC(A2:A17))<=1))
+SUMPRODUCT(
((A2:A17-TRUNC(A2:A17))>=0)*
((A2:A17-TRUNC(A2:A17))<=(1/6)))
Edit: As per the other answer, it's easier to read with MOD instead of TRUNC:
=SUMPRODUCT(
(MOD(A2:A17,1)>=0.625)*
(MOD(A2:A17,1)<=1))
+SUMPRODUCT(
(MOD(A2:A17,1)>=0)*
(MOD(A2:A17,1)<=(1/6)))
Explanation:
A2:A17-TRUNC(A2:A17) returns only the decimal part of the number - time
0.625 - 15:00 (3 pm)
1 - midnight
0 - midnight
=0.166667 or 1/6 - 4:00 (4 am)
I'm sure there are other ways of doing it but this one seems pretty simple and does not require a helper column.

Related

Is there a non-VBA way to calculate the average of the sum of two sets of columns?

I'm creating an excel spreadsheet to track when an item is received as well as when a response to the item having been received has been made (ie: my mail was delivered at 1:00pm (item received) but I didn't check the mail until 5:00pm (response to item having been received)).
I need to track both the date and time of the item being received and want to separate these in two separate columns. At the moment this translates to:
Column A: Date item received
Column B: Time item received
Column L: Date item was responded to having been received
Column M: Time item was responded to having been received
In essence I'm looking to run calculations on the response time between when the item is received and when it has been responded to (ie: average response time, number of responses in less than an hour, and even things like the number of responses that took between 2 and 3 hours where Bob was the person who responded).
The per-line pseudo code would look something like:
(Lr + Mr) - (Ar + Br) ' where L,M,A,B are the columns and 'r' is the row number.
An example, with the following data:
1. A B L M
2. 1/5/19 10:00 1/5/19 12:00
3. 1/5/19 21:00 1/6/19 1:00
4. 1/5/19 22:00 1/5/19 23:00
5. 1/6/19 3:00 1/6/19 4:00
The outcome for the average response time would be 2 hours (average(rows 2-5) = average(2, 4, 1, 1) = 2)
The number of items with an average response times would be as follows:
(<=1 hour) = 2
(>1 & <=2) = 2
(>2 & <=3) = 0
(>3) = 1
I don't know (or can find) a function that will perform this and then let me use it within something like a countifs() or averageifs() function.
While I could do this (fairly easily) in VBA, the practical implementation of this spreadsheet limits me to standard Excel. I suspect that sumproduct() will be fundamental to make this work, but I feel that I need something like a sumsum() function (which doesn't exist) and I'm not familiar with sumproduct() to better understand what to even look for to set something like this up.
If you are not so familiar with SUMPRODUCT() or the likes I would suggest one helper column. Like so:
You can see the formula used is:
=((C2+D2)-(A2+B2))
You can probably do all type of calculations on this helper column. Note, column is formatted hh:mm. However, if you want to look into SUMPRODUCT() you could think about these:
Formula in H2:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=1))
Formula in H3:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>1)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=2))
Formula in H4:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>2)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<3))
Formula in H5:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>3))
The helper column is the easiest approach. It gives you the time differences that you can then easily analyse however you want. Analysis without the helper column is possible, but the approach differs depending on what type of analysis you want to do.
For the example you provided, which is counting the number of time differences grouped into ranges, you would use the FREQUENCY function:
=FREQUENCY(C2:C5+D2:D5-A2:A5-B2:B5,F2:F4)
In F2:F4 (called the "bins"), enter the upper limit of each range you want to count. The Frequency function counts up to and including the first value, then counts from there up to and including the second value, and so on. Enter the bins as times, e.g. 1:00 for 1 hour.
Note that Frequency is an array-entered and an array-returning function. This you means you need to first select the range that will contain all output values, G2:G5 in this example, then enter the function, then press CTRL+SHIFT+ENTER
Also note that Frequency returns an array that is one element larger than the number of bins specified. The extra element is the count of all values greater than the largest bin specified.

#NUM! error when formula calculating % complete for future dates

I've got a worksheet that shows employee assignments, as well as their contract start and end dates. in column D I calculate the percent that this contract is completed.
My formula is working for current and past dates, but future dates result in #NUM!. I have a feeling this is because the calculation is either impossible or less than 0.
I've tried to correct this but it's currently beating me. Any suggestions to fix this?
Formula:
=IF(ISBLANK(B2),"",IF((DATEDIF(B2,TODAY(),"d")+1)/(DATEDIF(B2,C2,"d")+1)>99.99%,1,IFERROR((DATEDIF(B2,TODAY(),"d")+1)/(DATEDIF(B2,C2,"d")+1),0)))
Data:
A B C D
1 Name Start Date End Date Contract % Complete
2 Allen 8/21/17 8/24/18 100.00%
3 Billy 12/4/17 12/8/18 72.16%
4 Charles 9/6/18 12/28/18 #NUM!
The issue is that a Date can not be negative and DATEDIF(B2,TODAY(),"d") tries to return a negative date.
If the date is in the future then it is 0% finished.
Add an IFERROR to deal with that:
=IFERROR(IF(ISBLANK(B2),"",IF((DATEDIF(B2,TODAY(),"d")+1)/(DATEDIF(B2,C2,"d")+1)>99.99%,1,IFERROR((DATEDIF(B2,TODAY(),"d")+1)/(DATEDIF(B2,C2,"d")+1),0))),0)
Because 1 day to Excel is 1 we can get rid of the DATEDIF. Then using MAX and MIN to get rid of the nested IF and IFERRORs, we can simplify the formula to:
=IF(ISBLANK(B2),"",MAX(MIN((TODAY()-B2+1)/(C2-B2+1),1),0))

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.

How to sum the number of overlapping time frames in excel

Hoping someone can help,
I work for a fire department and i am trying to determine the number of times all our rigs on the road at emergencies at the same time. I have all the data from date, times, etc... So what i am looking for is an excel summation total that would display the sum of overlapping times that were greater than 3. So kinda as follows:
Rig Date Start Time End Time
1 1/1/2015 0703 0759
2 1/1/2015 0705 0823
3 1/1/2015 0706 0815
4 1/1/2015 0723 0759
1 1/1/2015 0802 0845
With more than three rigs on the road after 0723 it would grant me a total of one but then at 0802 rig 1 goes back out again meaning my total would increase by 2 and so on and so on. I dont have the slightest clue as to how to program this. I have three years of data i need to crunch through and something like this would help me greatly. Any help whatsoever is appreciated. Thanks in advance and lets see what you all come up with!
First, you might want to convert the times to Excel date-times (assuming you already applied Format as Table to your data, so all new formulas get populated for all rows automatically):
if the values are already Excel times, use:
=$B2 + C2
if you have integers like "703" (formatted as "0703"), use:
=$B2 + INT(C2/100)/24 + MOD(C2, 100)/24/60
or if you have values-as-text:
=$B2 + LEFT(C2, 2)/24 + RIGHT(C2, 2)/24/60
Don't forget to format the new columns using Custom Number format d.m. hh:ss or m/d hh:ss.
The next step is to count all ongoing deployments that end only after the current deployment started, i.e. use following formula as illustrated on screenshot:
=COUNTIFS(F$2:F2, ">" & E2)
Please make sure that the formula e.g. in row 13 looks like =COUNTIFS(F$2:F13, ">" & E13) to check that you are on the right track. Also none of the values can be 5 or more if you only have 4 rigs, otherwise you have an error in your data.
And to count number of times when all 4 rigs were in use, the formula looks like this:
=COUNTIFS($G$2:$G$13, 4)
In case you also want to sum the time while none rigs were available, add 2 more columns in your table. Column H in my illustration needs following array formula (entered by Ctrl+Shift+Enter):
=IF(G2=4, MIN(IF(F$2:F2 > E2, F$2:F2)), "")
And a normal formula in column I:
=IF(G2=4, H2-E2, "")
Don't forget to format numbers accordingly.
And do a simple sum: =SUM($I$2:$I$13).

Working Hours Excel Formula

I need to calculate the working hours elapsed between two dates and times, for example:
Holiday taken between 01/09/2014 and 05/09/2014
5 working days # 8 hours per day.
I need the result to show me how many working hours that would be. For example:
ANNUAL ENTITLEMENT: 89.9 Hours
DATE FROM DATE TO RETURN TO WORK HOURS REQUIRED HOURS REMAINING DATE
01/09/2014 05/09/2014 06/09/2014 40 49.90
I have no idea if this is even possible!
I am assuming these are given cells. if you type in the date to a cell you can click on a new cell and put uptop by the fx this
for example. In C1 you can type this into the fx. Make sure you put the equal sign.
=B1-A1
This is what is the dates in the cells
A1 = 1/9/2014
B1 = 5/9/2014
This will give you 120 which is the total days inbetween.
You will want to get the number of weeks so you can divide by 7.
You will multiply weeks by number of days worked which is 5
Then you want the weeks times 8 hours you can do this in C1
=(B1 - A1)/7 * 5 * 8
which gives you 685.7143
you need to also take into account weekends which a simple subtraction will not do. Firstly find the total number of days:
TOTAL_NUMBER_DAYS = B1-A1 + 1
then calculate how many weekends:
TOTAL_WEEKENDS = WEEKNUM(B1) - WEEKNUM(A1)
finally take the total days and subtract weekends:
NET_TOTAL_DAYS = TOTAL_NUMBER_DAYS - (TOTAL_WEEKENDS * 2)
TOTAL_HOURS = NET_TOTAL_DAYS * 8
I solved this recently and had a working solution initially in Excel 2013. Slightly adapted to work in 2007 (lack of 'Days()' function). We use it for reporting on support tickets (length of time between opening and closing a ticket).
Inputs are "Workday start", "Workday end" from which "Hours worked" and "Hours not worked" are calulated.
Hours worked =HOUR(WorkEnd-WorkStart)+(MINUTE(WorkEnd)+MINUTE(WorkStart))/60
Hours not worked = 24 - Hours worked
Further inputs are a table ("Data") with first two columns "Open" and "Close", which are dateserial cells.
Next column is standard numeric value "Gross hours" =(Data[[#This Row],[Close]]-Data[[#This Row],[Open]])*24
Next column is standard numeric value "Net workdays" =NETWORKDAYS(Data[[#This Row],[Open]],Data[[#This Row],[Close]])
Next column is standard numeric value "Net days" =MAX(1,DAY(Data[[#This Row],[Close]])-DAY(Data[[#This Row],[Open]]))
Next column is standard numeric value "Gross workhours" =IF(Data[[#This Row],[Gross hours]]>0,Data[[#This Row],[Gross hours]]-24*(Data[[#This Row],[Net days]]-Data[[#This Row],[Net workdays]]),0)
Last column is standard numeric value "Total work hours" =IF(Data[[#This Row],[Gross workhours]]<24,Data[[#This Row],[Gross workhours]],Data[[#This Row],[Gross workhours]]-(HoursNotWorked*Data[[#This Row],[Net workdays]]+HoursWorked))
This solution makes it trivial to adjust start and end work times, as well as accounting for any holidays (via a small change to the NETWORKDAYS() function to utilise the optional parameter).

Resources