Have a look here, how to calculate: Why does this not work? (logic to calculate an average and save the result)