Averaging times

SteveC

Board Regular
Joined
Mar 14, 2002
Messages
118
Hi
Averaging times. I have a column of racing times. The column to its right contains the average of the times starting from that line and every line above it. I was proud of myself for figuring out the formula to do it - until I realized that I was averaging it as if were a decimal number (158.4) instead of time (1:58.4) - One minute : fifty-eight seconds . and four fifths of a second. The last number (e.g. ".4")is from zero through 4 (or blank), and represents fifths of a second (Strange, but it's the way they do it.). The format (there is no choice) that it will have been previously input in and then automatically (by a button) copied to the "Times" column (DO) will be xxx.x . If it helps, I can have the DO and DP columns and their numbers formatted in any manner, if needed.

Is there a way to display an average on each line? Do the times have to be first put into the format of x:xx.x ? (-and if so, then how could I do that by formula or VBA?)
I would appreciate any help!

"Times" column: DO ... "Averages" column: DP ... Lines: 194 through 358
Here's what I *was* using on each line in DP:
=IF(OR($DO198="", $DO198>"*"),"",AVERAGE($DO$194:$DO198))

Exception: Certain times do not get included in any average. There is an asterisk after those (e.g. 202.1*). I was experimenting and found, to my surprise, that $DO194>"*" in my formula worked to find and exclude those times with asterisks. (Works for other characters, also.)

Thanks -SteveC

This was extensively edited on 10/5 09:50
This message was edited by SteveC on 2002-10-08 03:55
 
Aladin,
Thanks
Steve

TIMES....AVERAGE
02:00.2 02:00.2
01:55.1 01:57.6
01:59.1 01:58.1
01:59.3 01:58.4
02:00.0 01:58.7
02:01.0 01:59.1
02:01.4 01:59.4

formula: =AVERAGE($DP$194:$DP200)

If it's of interest, I wrote out the steps for manual calculation of the averages.
This message was edited by SteveC on 2002-10-08 03:53
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Aladin,
After re-reading your request, I believe this is what you wanted:
* The average of the first 7 entries (with decimal as fifths) 1:59.3
* (The average using the fifths amount as if they were 10ths = 1:59.4 (decimal).)
* (The average of ONLY the Fifths in each entry (not using mm or ss) = 2 (from 1.57 fifths rounded up).)

Thanks.
Steve

-------------------------------------
Calculations for averaging ONLY the Fifths in each entry (not mm or ss):
2+1+1+3+4= 11 (5ths) (two of the seven were zero)
x2 = 22 (22 tenths)
22 / 7 entries= 3.14 AVERAGE in 10ths
/2 (for 5ths)= 1.57 AVERAGE in 5ths
Round 1.57 up to TWO fifths = 2
-------------------------------------
-------------------------------------


My method for calculating the average using the all of the data from each entry, below.

STEPS TO CALCULATE AVERAGE
---------------------------------------------------
1) SEPARATLY SUM THE PARTS OF EACH OF THE RACE TIME ENTRIES

(DP194:DP200)
02:00.2
01:55.1
01:59.1
01:59.3
02:00.0
02:01.0
02:01.4

. . . . . . . M . . S . . . F(5ths)
SUM= 11 : 175 . 11
----------------------------------------------------
2) CONVERT MINUTES TO SECONDS and FIFTHS OF A SECOND (base 5) TO DECIMAL (base 10) : SUM THE RESULTS TO ACHIEVE THE COMBINED TOTAL SECONDS FOR ALL ENTRIES

((M x 60) + S) + ((F x 2) /10) = Total Seconds for all Entries
11 x 60 + 175 + 22/10 = (660+175+2.2) = 837.2 Total Seconds ("TS") -in decimal
----------------------------------------------------
3) CALCULATE THE AVERAGE OF THE RACE ENTRIES IN SECONDS

TS/#-of-Entries = AVERAGE IN SECONDS (" AVS ")
837.2/7 = 119.6 AVerage in Seconds -in decimal
----------------------------------------------------
4) CONVERT THE AVERAGE IN SECONDS (AVS DECIMAL) INTO MINUTES : SECONDS . FIFTHS OF A SECOND

.....a) CONVERT SECONDS INTO MINUTES: CALCULATE THE NUMBER OF TIMES THAT AVS IS DIVIDED EVENLY BY 60

AVS/60 = EXTRACT WHOLE MINUTES ONLY (NO fraction or decimal)
119.6/60 = 1 minute (1:xx.x)

.....b) COPY THE REMAINDER OF WHOLE SECONDS (which is less than 60) FROM STEP "a" ABOVE
(119.6 - 60) = 59.6 = 59 seconds (1:59.x)

.....c) CONVERT DECIMAL TO FIFTHS OF A SECOND

[decimal #]/2 = FIFTHS OF A SECOND
6/2 = 3 fifths of a second (1:59.3)

5) RESULT: AVERAGE OF RACE TIME ENTRIES: EXPRESSED IN STANDARD TIME FORMAT - WITH THE FRACTION AS FIFTHS (base 5)

m:ss.f = minutes : seconds . fifths
1:59.3
This message was edited by stevec on 2002-10-09 19:19
 
Upvote 0
I am copying this from an answer to another post on averaging with fifths, that I failed to delete. Sorry.
SteveC

Mala MrExcel MVP Joined: Apr 05, 2002 Posts: 11
Posted: 2002-10-09 15:15

There seems to be no direct way to do this - so far as I know, Excel will not go beyond displaying seconds to decimal based on 10.
To display (not use for calculation) the values in a format where the digit after the decimal point represents the fifths of a second, you need to define a custom function as under:

Function Sec5Txt(Tm As Single) As String
FullTime = WorksheetFunction.Floor(Tm, 1 / 86400)
ExtraTime = Tm - FullTime
Parts5F = WorksheetFunction.Floor(ExtraTime, 1 / (86400 * 5))
Parts5C = WorksheetFunction.Ceiling(ExtraTime, 1 / (86400 * 5))
If ExtraTime - Parts5F >= Parts5C - ExtraTime Then Parts5 = Parts5C Else Parts5 = Parts5F
Parts5 = Parts5 / (1 / (86400 * 5))
Sec5Txt = WorksheetFunction.Text(Tm, "hh:mm:ss") & "." & WorksheetFunction.Text(Parts5, "0")
End Function

For row 199 of the formula that you have on each row in DQ, use the formula: =Sec5Txt(AVERAGE($DP$194:$DP199))
instead of just AVERAGE($DP$194:$DP199).
Note that this function returns text - using this with the VALUE() function would interpret the digit after the decimal point as 'tenths' not 'fifths'.

If you wish to use the average values for subsequent calculations (with accuracy as obtained after rounding to fifths) you would need to use the following function

Function Sec5Num(Txt As String) As Date
Time1 = TimeValue(Left(Txt, Len(Txt) - 2))
Time2 = Val(Right(Txt, 1)) / 5 / 86400
Sec5Num = Time1 + Time2
End Function

A typical formula would be =Sec5Num(Ref) where Ref refers to a cell containing string calculated by the Sec5Txt function.


If you wish to use the average values for subsequent calculations with the original accuracy simply use AVERAGE($DP$194:$DP199) again without refering to DQ. I use XL 2K and can't find
the number format hh:mm:ss.f - so I used hh:mm:ss.0

Hope this helps...

_________________
Mala Singh
MrExcel Graphics & Engineering Division

[ This Message was edited by: Mala on 2002-10-09 15:34 ]
 
Upvote 0
Thanks Steve - I was just going to update this thread with a reference to my post when I saw you have already done it...
 
Upvote 0
Aladin,
Was the info that I sent "Posted: 2002-10-08 18:31" what you wanted?


Mala,
Thank you for the suggestion, but I couldn't get any part of it to work. I get a six digit # for minutes in the time column (DP) and the #Name? error on one line in the average column (DQ) and the rest of DQ has 6 digit #'s.

Steve
This message was edited by stevec on 2002-10-11 03:02
 
Upvote 0
Copy the folowing code to a module in the VBA Project of the SAME workbook in which you'll use the functions - not the VBA Project some other workbook.

Function Sec5Txt(Tm As Single) As String
FullTime = WorksheetFunction.Floor(Tm, 1 / 86400)
ExtraTime = Tm - FullTime
Parts5F = WorksheetFunction.Floor(ExtraTime, 1 / (86400 * 5))
Parts5C = WorksheetFunction.Ceiling(ExtraTime, 1 / (86400 * 5))
If ExtraTime - Parts5F >= Parts5C - ExtraTime Then Parts5 = Parts5C Else Parts5 = Parts5F
Parts5 = Parts5 / (1 / (86400 * 5))
Sec5Txt = WorksheetFunction.Text(Tm, "hh:mm:ss") & "." & WorksheetFunction.Text(Parts5, "0")
End Function

Function Sec5Num(Txt As String) As Date
Time1 = TimeValue(Left(Txt, Len(Txt) - 2))
Time2 = Val(Right(Txt, 1)) / 5 / 86400
Sec5Num = Time1 + Time2
End Function

Make sure to spell the names of the functions correctly in the formulas - the NAME error indicates either incorrect spelling or inability of Excel to find the function in the VBA project.

If this still doesn't work, send me your workbook (mala_rs_singh@rediffmail.com) and I'll set it up for you

I'll try to upload a sample data set here...
 
Upvote 0
Fifths.xls
ABCDEF
1Time1Time2Time3AverageStr @fifthBack to dec
200:10:03.0100:10:03.0100:10:03.0100:10:03.0100:10:03.000:10:03.0
300:10:03.0200:10:03.0200:10:03.0200:10:03.0200:10:03.000:10:03.0
400:10:03.0300:10:03.0300:10:03.0300:10:03.0300:10:03.000:10:03.0
500:10:03.0900:10:03.0900:10:03.0900:10:03.0900:10:03.000:10:03.0
600:10:03.1000:10:03.1000:10:03.1000:10:03.1000:10:03.100:10:03.2
700:10:03.1100:10:03.1100:10:03.1100:10:03.1100:10:03.100:10:03.2
800:10:03.1200:10:03.1200:10:03.1200:10:03.1200:10:03.100:10:03.2
900:10:03.2200:10:03.2200:10:03.2200:10:03.2200:10:03.100:10:03.2
1000:10:03.2300:10:03.2300:10:03.2300:10:03.2300:10:03.100:10:03.2
1100:10:03.2900:10:03.2900:10:03.2900:10:03.2900:10:03.100:10:03.2
1200:10:03.3000:10:03.3000:10:03.3000:10:03.3000:10:03.200:10:03.4
1300:10:03.3100:10:03.3100:10:03.3100:10:03.3100:10:03.200:10:03.4
1400:10:03.3800:10:03.3800:10:03.3800:10:03.3800:10:03.200:10:03.4
1500:10:03.3900:10:03.3900:10:03.3900:10:03.3900:10:03.200:10:03.4
1600:10:03.4000:10:03.4000:10:03.4000:10:03.4000:10:03.200:10:03.4
1700:10:03.4100:10:03.4100:10:03.4100:10:03.4100:10:03.200:10:03.4
1800:10:03.4200:10:03.4200:10:03.4200:10:03.4200:10:03.200:10:03.4
1900:10:03.4300:10:03.4300:10:03.4300:10:03.4300:10:03.200:10:03.4
2000:10:03.4800:10:03.4800:10:03.4800:10:03.4800:10:03.200:10:03.4
2100:10:03.4900:10:03.4900:10:03.4900:10:03.4900:10:03.200:10:03.4
2200:10:03.5000:10:03.5000:10:03.5000:10:03.5000:10:04.300:10:04.6
2300:10:03.5100:10:03.5100:10:03.5100:10:03.5100:10:04.300:10:04.6
2400:10:03.5200:10:03.5200:10:03.5200:10:03.5200:10:04.300:10:04.6
2500:10:03.5300:10:03.5300:10:03.5300:10:03.5300:10:04.300:10:04.6
2600:10:03.5800:10:03.5800:10:03.5800:10:03.5800:10:04.300:10:04.6
Fifths

This message was edited by Mala on 2002-10-16 03:08
 
Upvote 0
Sample data uploaded...thanks Colo and Ivan!!! A lovely utility this one...

SteveC: Apropos of seeing a 6-digit number in place of time ...don't forget to format the cells 'hh:mm:ss.0'
Send me the workbook if you still have problems..
 
Upvote 0
Resending privately sent msg on msgboard:

Hi Steve,
Here's the code for a function to return a string formatted as mm:ss.f for average time. Copy it to a module. See the worksheet displayed below to understand how the data is set up and how the formulas are input.
Please check if it is working correctly and write back.

Function Avg5(Rng As Range) As String
Min = 0
Sec = 0
Fifth = 0
Times = 0
For Each cell In Rng
TV = 0
TV = TimeValue(cell)
If TV > 0 Then
Times = Times + 1
Min = Min + Val(Left(cell, 2))
Sec = Sec + Val(Mid(cell, 4, 2))
Fifth = Fifth + Val(Right(cell, 1))
End If
Next
Secs = Min * 60 + Sec + Fifth / 5
AvgSecs = Secs / Times
Min1 = Int(AvgSecs / 60)
Sec1 = Int(AvgSecs) - Min1 * 60
Fifths = (AvgSecs - Int(AvgSecs)) * 10 / 2
Avg5 = WorksheetFunction.Text(Min1, "00") & ":" & WorksheetFunction.Text(Sec1, "00") & "." & WorksheetFunction.Text(Fifths, "0")
End Function
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top