Calculate average from dates in text - excel

I'm using this formulas:
=DATEDIF(B9,S9,"d") & " Days " & TEXT(S9-B9, "h:m") & " hrs:min"
=DATEDIF(B10,S10,"d") & " Days " & TEXT(S10-B10, "h:m") & " hrs:min"
etc..
And now i need to have a formula that calculates the average of those dates. The problem is that they are in text and excel cannot calculate average.. Would appreciate any input. Thanks

Your formula isn't a reliable method for calculating days and hours between two dates. Consider where B9 is 1st Jan 2013 at 22:00 and S9 is the next day 2nd Jan at 06:00 - there are only 8 hours between those two "timestamps" but your formula will give the result
1 Days 8:00 hrs:min
better to use this version
=INT(S9-B9) & " Days " & TEXT(S9-B9, "h:m") & " hrs:min"
That will give correct results in all cases
For the average you can use a formula like this
=INT(AVERAGE(S9:S18)-AVERAGE(B9:B18)) & " Days " & TEXT(AVERAGE(S9:S18)-AVERAGE(B9:B18), "h:m") & " hrs:min"
where you have data in rows 9 to 18

Consider the following:
Formulas:
C2 = B2-A2
(same for rows 2 through 6)
C7 = AVERAGE(C2:C6)
D2 = INT(C2) & " Days " & TEXT(C2, "h:mm") & " hrs:min"
(same for rows 2 through 7)

Related

How to calculate business hours elapsed in excel

I need to calculate business hours elapsed in MS Excel. Here i have two dates, start and End date with respective timings. Some places i might not have end date and timings. Business hours are 7AM EST - 17 PM EST. how can i calculate number of business hours elapsed here ? (Excluding Weekends)
Tried "=IF(ISBLANK(P2),(NETWORKDAYS(O2,NOW())-1)*("17:00"-"7:00")+IF(NETWORKDAYS(NOW(),NOW()),MEDIAN(MOD(NOW(),1),"17:00","7:00"),"17:00")-MEDIAN(NETWORKDAYS(O2,O2)MOD(O2,1),"17:00","7:00"),(NETWORKDAYS(O2,P2)-1)("17:00"-"7:00")+IF(NETWORKDAYS(P2,P2),MEDIAN(MOD(P2,1),"17:00","7:00"),"17:00")-MEDIAN(NETWORKDAYS(O2,O2)*MOD(O2,1),"17:00","7:00"))", need to exclude holidays as well here.
You can split this into three components (fraction of first day, full workdays, fraction of last day)
Lets start with the middle part. Here you can use NETWORKDAYS and subtract the start and end date. I am assuming a start date in A1 and end date in B1. In order to exclude holidays you need to maintain a list of holidays in your sheet. The formula assumes that this list is in range C1:C10. The results is multiplied by 10 as there are 10 hours in your workday.
=MAX((NETWORKDAYS(A1,B1,C1:C10)-NETWORKDAYS(A1,A1,C1:C10)-NETWORKDAYS(B1,B1,C1:C10))*10,0)
For the fractions you will need to determine if the day itself is a holiday, we use the NETWORKDAYS function again as a factor which will be either 0 or 1. Now we only need to determine the hours to add for the day. Depending on the granularity you want you can consider hours, minutes or even seconds. I will use hours and minutes as a fraction (minutes/60 = hours).
For the first day you get
=MAX(17-MAX(HOUR(A1)+MINUTE(A1)/60,10),0)*NETWORKDAYS(A1,A1,C1:C10)
For the last day you get
=MAX(MIN(HOUR(B1)+MINUTE(B1)/60,17)-10,0)*NETWORKDAYS(B1,B1,C1:C10)
Putting it all together leaves us with:
=MAX(17-MAX(HOUR(A1)+MINUTE(A1)/60,10),0)*NETWORKDAYS(A1,A1,C1:C10)+MAX((NETWORKDAYS(A1,B1,C1:C10)-NETWORKDAYS(A1,A1,C1:C10)-NETWORKDAYS(B1,B1,C1:C10))*10,0)+MAX(MIN(HOUR(B1)+MINUTE(B1)/60,10)-10,0)*NETWORKDAYS(B1,B1,C1:C10)
I believe this UDF will do what you need.
It calculates the hours and returns it as a float, then you need to multiply that with 24 to get the hours.
Function workhours(startdate As Date, enddate As Date)
Opentime = "7:00"
Closetime = "17:00"
Fulldays = Int(enddate - startdate) - 1
DayOneHours = CDate(Year(startdate) & "-" & Month(startdate) & "-" & Day(startdate) & " " & Closetime) - startdate
BeforeOpen = CDate(Year(startdate) & "-" & Month(startdate) & "-" & Day(startdate) & " " & Opentime) - startdate
HoursDayOne = DayOneHours - BeforeOpen
If enddate < CDate(Year(enddate) & "-" & Month(enddate) & "-" & Day(enddate) & " " & Opentime) Then
HoursLastDay = 0
Else
HoursLastDay = enddate - CDate(Year(enddate) & "-" & Month(enddate) & "-" & Day(enddate) & " " & Opentime)
End If
workhours = Fulldays * (CDate(Closetime) - CDate(Opentime)) + HoursDayOne + HoursLastDay
End Function
Use it in Excel like:
=workhours(A1,B1)*24

How to start from 0 using ROW()

So I have this formula source here
=REPT(CHAR(9); CODE(A1)-65) & SUMPRODUCT(($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1)-1)) & "." & IF(CODE(A1)>65;SUMPRODUCT(($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & IF(CODE(A1)>66;SUMPRODUCT(($A$1:$A$200="C")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & CHAR(9) & B1
Which give us this:
The question is: How do I start from 0?
Starting from zero mean,
Title 1 = 0. Title 1
Title 2 = 1. Title 2
Subtitle 3 = 1.1 Subtitle 3
Just found the solution, you need too Subtract 1 from the first SUMPRODUCT
Thanks for you help everyone
=REPT(CHAR(9); CODE(A1)-65) & SUMPRODUCT(($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1)))-1 & "." & IF(CODE(A1)>65;SUMPRODUCT(($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="A")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & IF(CODE(A1)>66;SUMPRODUCT(($A$1:$A$200="C")*(ROW($A$1:$A$200)<=ROW(A1))*(ROW($A$1:$A$200)>=MAX(ROW($A$1:$A$200)*($A$1:$A$200="B")*(ROW($A$1:$A$200)<=ROW(A1))))) & ".";"") & CHAR(9) & B1
In general, to create a column of values starting from zero and increasing by one, pick any cell and enter:
=ROWS($1:1)-1
and copy downward.

How to convert a string to a date in excel?

I have the date and time in the following format in Excel:- 12Jun17/1802 How do I convert this to excel date and time format? I have tried Format Custom but I am unable to make this work.
Excel stores dates and times as days and fractions of a day since 1/1/1900. The string you show is being seen only as text.
One way to convert it is to use string functions to format it into something Excel will recognize as a date/time:
=LEFT(A2,2) & " " & MID(A2,3,3) & " " & MID(A2,6,2) & " " & TEXT(RIGHT(A2,4),"00\:00")
--> 12 Jun 17 08:02
and then convert that to a number:
=--(LEFT(A2,2) & " " & MID(A2,3,3) & " " & MID(A2,6,2) & " " & TEXT(RIGHT(A2,4),"00\:00"))
You can now format that number with any of the date/time formats.

Excel improving date diff function

I've defined the following formula in Excel
=DATEDIF(B595;TODAY();"y") & " years, " & DATEDIF(B595;TODAY();"ym") & " months, " & DATEDIF(B595;TODAY();"md") & " days"
But it shows a result like:
0 years, 0 months, 20 days
I would prefer to see:
20 days
Can I use a VBA function to get a nicer result? Or a formula?
Just add If statements to the formula that will remove the component if DateDif evaluates to zero:
=IF(DATEDIF(B595;TODAY();"y")=0;"";DATEDIF(B595;TODAY();"y") & " years, ") & _
IF(DATEDIF(B595;TODAY();"ym")=0;"";DATEDIF(B595;TODAY();"ym") & " months, ") & _
IF(DATEDIF(B595;TODAY();"md")=0;"";DATEDIF(B595;TODAY();"md") & " days, ")
I broke the formula into three lines so its readable here, but it should be inputted as one line

Is there a way to quickly change the row number when doing = B1, = B2, ect. for thousands of rows?

This is what I am needing to put into Column A
= B1 & " " & C1 & " " & D1 & " " & E1 & " " & F1 & " " & G1 & " " & H1 & " " & I1
wherein the numbers will correspond to the current row that it is pasted in. Is there a faster way than simply pasting it in and manually changing the 1's to 2's, or to 3's or to 37892's?
You would string together a bunch of formulas:
=INDEX(B:B,Row()) & " " & INDEX(C:C,Row()) & ...
But if all you want is to put the formula in J1 and copy it down, then use your original formula. Put it in J1. then do one of the following:
Click on the lower right corner and drag down as far as you want.
Highlight J1 and all the cells below in which you want the formula. Go to Fill --> Down
Either of these will automatically change the row number on your original formula.

Resources