CALCULATIONS WITH TOTALS

Moderators: Phil Winkler, Graham Smith, Pete Tabord

CALCULATIONS WITH TOTALS

Postby Peter Wilson » Mon Jan 10, 2011 2:09 pm

CALCULATING TOTALS. I'm sure in the past I have been able to do this but seem to be having a senior moment and not getting any results so any help would be appreciated.

I simply want to add up a sequence of records and then divide them by another total from the same sequence. So I have two fields- AMOUNT and NUMBER and I want a total for each then I want to divide the total of AMOUNT by the total of NUMBER to get an average. I have used
AMOUNT : SUM;
NUMBER : SUM.

and that produces the totals okay , say AMOUNT= 25, NUMBER = 10 but what I also want is
(AMOUNT : SUM)/(NUMBER : SUM) to give me 25/10= 2.5.

Is there any way to achieveit- sure there must be!
Peter Wilson
 
Posts: 44
Joined: Wed Jul 02, 2008 8:50 am
Has thanked: 0 time
Been thanked: 0 time
 

Re: CALCULATIONS WITH TOTALS

Postby Phil Winkler » Mon Jan 10, 2011 4:43 pm

Peter, the statistical operators like SUM won't work. Instead you need two variables to do your work for you.

define "tAmount" number .
define "tNum" number .

for formname
;
tAmount := tAmount + Amount .
tNum := tNum + 1 .
list records
Amount : sum ;
Number : sum ;
tAmount / tNumber . --put this after the .end
Phil Winkler
PLM Consulting, Inc.
pwinkler@plmconsulting.com
Phil Winkler
 
Posts: 889
Joined: Fri Sep 07, 2007 12:45 pm
Has thanked: 0 time
Been thanked: 0 time
 

Re: CALCULATIONS WITH TOTALS

Postby Peter Wilson » Mon Jan 10, 2011 5:34 pm

Thanks Phil, will give it a go.
Peter Wilson
 
Posts: 44
Joined: Wed Jul 02, 2008 8:50 am
Has thanked: 0 time
Been thanked: 0 time
 
 

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron