Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Averaging group totals 1

Status
Not open for further replies.

bascy

Programmer
Mar 6, 2001
53
NL
I have a report where in the detail lines a variable is set when a line with a certain line comes by.
The first groupfooter contains a max-variable of this one.
in the outer group footer i want an average of the different values from group1
Code:
GH1: Customer 1
  GH2: order 1 (hidden)
    D: orderline 1 (hidden, set var @a to 0)
    D: orderline 2 (hidden, set var @a to 34)
  GF2: display max(@a) i.e. 34
  GH2: order 2 (hidden)
    D: orderline 1 (hidden, set var @a to 54)
    D: orderline 2 (hidden, set var @a to 0)
    D: orderline 2 (hidden, set var @a to 0)
  GF2: display max(@a) i.e. 54
GF1: Display average of the max(@a) i.e. 44

... how do i do that???



Bascy
Network manager at
 
Which version of Crystal? Have you looked at running totals? They can do averages of data on a group-by-group basis

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Do two running totals using the same rules at different group levels.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Reading my own post back .. i see i'm not telling the whole story...

In de detail-lines there are two variables actually, and they are both max'ed at GF2 level. These are a starttime and an endtime, which are subtracted to yield a duration.

At GF2 there is a variable @b which calculates (MaxEndtime - Maxstartime). i wouold liek to average this @b variable, but i can't select it when i create a new running total ...

Bascy
Network manager at
 
You can do this using additional variables. Since you haven't shown us the actual variables, I will explain this generically. To average a group #2 variable at the group #1 level, you would create three formulas:

//{@reset} to be placed in GH1:
whileprintingrecords;
numbervar sumx := 0;
numbervar cnt := 0;

//{@accum} to be placed in GF2:
whileprintingrecords;
numbervar yourvar;//use your variable name here and below
numbervar sumx := sumx + yourvar;
numbervar cnt := cnt + 1;

//{@display} to be placed in GF1:
whileprintingrecords;
numbervar sumx;;
numbervar cnt;
sumx/cnt

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top