Average Formula Time Based Calculation

mianmazher

Active Member
Joined
Jan 24, 2004
Messages
412
Book2
ABCD
1TimeConsumption
2Start10:0045
315:2546.2
420:2547
540:00:0048
650:10:0046
7End60:00:0045.25
8
9Average46.464525
Sheet1


In Column B I have the time values in the text format which represent minutes and seconds

in Column A I have to write the start and the Stop as shown

If start and stop are in the position as shown above then the average should be 46.464525

If the start is entered in A3 and End in A7 then the Average should be

46.664525

in the same way if the end is shifted up or down the average changes automatically


Hope that u people understand what I trying to say


Waiting for someone to help


Regards

Mian Mazher
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Just a typo, got the columns wrong, this works if you apply it to the layout in my last post.


=SUMPRODUCT(INDEX(C1:C10,MATCH("Start",A1:A10,0)):INDEX(C1:C10,MATCH("End",A1:A10,0))*INDEX(D1:D10,MATCH("Start",A1:A10,0)):INDEX(D1:D10,MATCH("End",A1:A10,0)))/SUM(INDEX(D1:D10,MATCH("Start",A1:A10,0)):INDEX(D1:D10,MATCH("End",A1:A10,0)))
 
Upvote 0
Hi!
I know that this is possible with formula.
But lets try VBA for ease.
Book1
ABCDEFG
1Case2
2ActualTimeConsumptionTime(Numbers)
30:10:004510.00
40:15:2546.215.42
5Start0:20:254720.424720.42
60:40:004840.004819.58
7End0:50:104650.174610.17
81:00:0045.2560.00
9Average47.18771
10Average47.1877076
11
12InputtoUDF
Sheet3



The code!<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> AVERTIME(TABLE<SPAN style="color:#00007F">As</SPAN> Range)<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Double</SPAN><SPAN style="color:#00007F">Dim</SPAN> P()<SPAN style="color:#00007F">Dim</SPAN> ST()<SPAN style="color:#00007F">Dim</SPAN> COMP()<SPAN style="color:#00007F">ReDim</SPAN> P(TABLE.Rows.Count)<SPAN style="color:#00007F">ReDim</SPAN> ST(TABLE.Rows.Count)<SPAN style="color:#00007F">ReDim</SPAN> COMP(TABLE.Rows.Count)<SPAN style="color:#00007F">For</SPAN> I = 1<SPAN style="color:#00007F">To</SPAN> TABLE.Rows.Count
    P(I) = TABLE(I, 1)
    ST(I) = TABLE(I, 2) * 24 * 60
    COMP(I) = TABLE(I, 3)<SPAN style="color:#00007F">Next</SPAN> I<SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(P)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(P)
    <SPAN style="color:#00007F">If</SPAN> UCase(P(I)) = "START"<SPAN style="color:#00007F">Then</SPAN>
    STARTX = I
    <SPAN style="color:#00007F">ElseIf</SPAN> UCase(P(I)) = "END"<SPAN style="color:#00007F">Then</SPAN>
    ENDX = I
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Next</SPAN> I
PREVTIME = 0
SUMP = 0
SUMX = 0<SPAN style="color:#00007F">For</SPAN> I = STARTX<SPAN style="color:#00007F">To</SPAN> ENDX
    SUMP = SUMP + (ST(I) - PREVTIME) * COMP(I)
    SUMX = SUMX + (ST(I) - PREVTIME)
    PREVTIME = ST(I)<SPAN style="color:#00007F">Next</SPAN> I
AVERTIME = SUMP / SUMX<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Function</SPAN></FONT>
 
Upvote 0
fairwinds said:
Just a typo, got the columns wrong, this works if you apply it to the layout in my last post.


=SUMPRODUCT(INDEX(C1:C10,MATCH("Start",A1:A10,0)):INDEX(C1:C10,MATCH("End",A1:A10,0))*INDEX(D1:D10,MATCH("Start",A1:A10,0)):INDEX(D1:D10,MATCH("End",A1:A10,0)))/SUM(INDEX(D1:D10,MATCH("Start",A1:A10,0)):INDEX(D1:D10,MATCH("End",A1:A10,0)))

A weighted average... It seems waters are cleared up.

All this can be a bit shorter:
WeightedAvg.xls
ABCDEF
1Case2Start3
2ActualTimeConsumptionEnd4
310:004510.00
415:2546.215.4247.66207
5Start20:254720.42
640:004840.00
7End50:104650.17
860:0045.2560.00
Sheet1


D3:

=(IF(LEN(B3)<6,"0:"&B3,B3))*1440

F1, copied to F2...

=MATCH(E1,A3:A8,0)

E4 (computes the weighted average)...

=SUMPRODUCT((INDEX(D3:D8,F1):INDEX(D3:D8,F2))*(INDEX(C3:C8,F1):INDEX(C3:C8,F2)))/SUM((INDEX(D3:D8,F1):INDEX(D3:D8,F2)))
 
Upvote 0
Sir Aladin


Really not seen a one like u (I think the most genius Of all in this Forum)

all have provided a solution but yours solution is the easiest)


Thanks


REgards


Mian Mazher
 
Upvote 0
Hi Sir Aladin

Again Facing the problem.


The average should be 47.18771 instead of 47.662069 as computed below

The start time is 20.42

The end time is 50.17

(20.42*47)+((40.00-20.42)*48)+((50.17-40)*46)/50.17


I Hope this Helps to solve my problem


Regards
 
Upvote 0
My guess as I cannot view the formulas:

The formula in F2 should show 5
Change the formula in F1 to =MATCH(E1,$A$3:$A$8,0) before dragging it to F2.
 
Upvote 0
hi fairwinds

Problem not solved


Average comming 46.9080633

instead of comming 47.18771


Plz help whats wrong and where


Regards

Mian Mazher
 
Upvote 0
Ok,

Apart from the correction I mentioned before;

Here I inserted one column and changed the SUMPRODUCT formula.

Actually I really dont understand this average calculation, but anyway:

In E3 and dragg down: =IF(ROW()-2=$G$1,D3,D3-D2)

In F4: =SUMPRODUCT((INDEX(E3:E8,G1):INDEX(E3:E8,G2))*(INDEX(C3:C8,G1):INDEX(C3:C8,G2)))/INDEX(D3:D8,G2)
Book2
ABCDEFG
1Case2Start3
2ActualTimeConsumptionEnd5
310:004510.0010.00
415:2546.215.425.4247.18770764
5Start20:254720.4220.42
640:004840.0019.58
7End50:104650.1710.17
860:0045.2560.009.83
9
Sheet5
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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