This topic is locked

Calculate Average

3/17/2004 7:12:29 AM
ASPRunnerPro General questions
author

Hello,
I just downloaded this great program for a try out.

But I have a question, can I calculate an average of the inserted values in one row?

I have an Table with the fields ID, Date, Weight1, Weight2.....Weight30, AverageWeight.

It is not all of the Weight fields that has a value all the time, only sometimes that alla weight fields is filled.

Can you make it som that it feel that maybe just 3 of the weight fields has an value and then make on average to the field AvergaeWeight?
Hope you could help me!

Sergey Kornilov admin 3/17/2004

Here is what you can do to calculate column averages. You need to modify Sub LoopRs in ..._list.asp for this purpose. See my changes in bold.

' display table with results

sub loopRs(rsData,nPageSize)
Total1=0

Total2=0


' Pagination:

dim iShadeTheDetail

dim iNumberOfRows

iNumberOfRows = 0

if isObject(rsData) then

  ' Pagination: UNTIL iNumberOfRows>=maxrecs

  DO  UNTIL rsData.eof OR iNumberOfRows>=nPageSize
  Total1 = Total1 + rsData("Field1")

  Total2 = Total2 + rsData("Field2")

...
  Loop

 

 



Total1 = Total1/iNumberOfRows

Total2 = Total2/iNumberOfRows

response.write "<tr class=blackshade><td class=blackshade>" & Total1 & "</td><td>" & Total2 & "</td></tr>"

end if

end sub


I hope this helps.

501035 3/18/2004

Hi again.
That was not realy wath I was after.
This code is calculating just as you say, the average in a column.

But wath I am after, is the ability to calculate the average of a couple of inserted weigths in the same row, to a field named AverageWeight.

Is this possibly, or Is it just possibly to calculate in columns?