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

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))

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.

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

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.

Get Value of first Pair

I have this file
Date | Time | Table | Checkin Time | Bill Number ..| .. |
7/1/2018 **18:03:48** **6** **18:03:48** **4332**
7/1/2018 18:11:23 **6** **18:03:48** **4332**
7/1/2018 18:23:10 **6** **18:03:48** **4332**
7/1/2018 19:24:11 8 19:24:11 4333
7/1/2018 19:56:17 8 19:24:11 4333
7/1/2018 20:31:11 *6 20:31:11 4332*
I need to calculate Checkin Time which is 1st time of table number and bill number.
For example See one customer checkin at 18:03:48 with table number 6
His Bill number is 4332 .
So for table number 6 and Bill number 4332 chekin time will be 1st time
which is 18:03:48.
So I applied the formula:
=IF(AND(E3=E2,C3=C2,A3=A2),D2,MIN(OFFSET(E3,0,-3,MATCH(0,(E3:E$35470=E3)*(C3:C$35470=C3)*(A3:A$35470=A3),0)-1,1)))
But the value changes at 6th row .
It's giving 20:31:11 as checkin time .
It should be 18:03:48 because the 6th row table number and bill number is same as 1st one.
So How do I make it possible, to calculate the checkin time as per 1st time who have same bill and table number , no matter which row .
Here is the excel file I have uploaded to Google drive.
Here is the screenshot.
Edit:- Formula by #jeeped work, But as the log is of 30 days
The data keeps repeating the other day too.
Can it be done by giving some unique date value ?
If you don't have the newer MINIFS and MAXIFS, use AGGREGATE to achieve the same result.
=AGGREGATE(15, 7, ((A$2:A$7)+(B$2:B$7))/((C$2:C$7=C2)*(E$2:E$7=E2)), 1)
Format the result any way you want; as date and time, time only, etc.
You can make use of an array formula combining INDEX+MATCH to return the earliest time value that matches your conditions first. In cell D2, enter the following:
=INDEX($B$2:$B$7,MATCH(1,($C$2:$C$7=C2)*($E$2:$E$7=E2),0))
When returning, be sure to press CONTROL+SHIFT+ENTER instead of just ENTER to make sure the formula calculates correctly.
#Jeeped's answer is spot on, here is an adjustment for the formula to work over multiple days that have the same table numbers and bill numbers:
=AGGREGATE(15, 7, ((A$2:A$13)+(B$2:B$13))/((C$2:C$13=C2)*(E$2:E$13=E2)*(A$2:A$13=A2)), 1)
All I did was add this extra conditional argument, that checks if the "Date" is the same:
*(A$2:A$13=A2)

How to compare hours with numbers in excel?

I am making a task sheet for my students and I have written the following code:
=IF(J35-K35>5,"Task 1",IF(J35-K35>3,"Task 2",IF(J35-K35>2,"Task 3", IF(J35-K35>0,"Task 4",IF(K35-J35<1,"Task 5",IF(K35-J35<3,"task 6",IF(K35-J35>3,"Task 7")))))))
The cell K35 contains "Total hours worked" and
The cell J35 contains "Total hours required".
Their format is in [h]:mm
The problem I am facing here is that it is showing me output for only 2 conditions - for the one which is greater than 0 (Task 4) and the other which is less than 1 (task 5). None of the other conditions are getting executed. I need a way in which I can compare hours with numbers.
How can I solve this problem?
If the cells contain times, the calculation J35-K35 will return a number between 0 and 1 for a positive value, between -1 and 0 for a negative value. The formula will use the underlying values, not what they will look like if formatted as time.
The value of one hour, formatted as general is 0.041666667. You can either use that and its multiples in your formula or multiply the result of the subtraction by 24 to arrive at numbers where the part before the decimal point is the number of hours, so your formula could be
=IF((J35-K35)*24>5,"Task 1",IF((J35-K35)*24>3,"Task 2",IF((J35-K35)*24>2,"Task 3", IF((J35-K35)*24>0,"Task 4",IF((K35-J35)*24<1,"Task 5",IF((K35-J35)*24<3,"task 6",IF((K35-J35)*24>3,"Task 7")))))))

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).

Resources