Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Adding 2 averages

edited March 2004 in General
I want to add the averages from 2 columns but the result I get is the sum of
the totals of the 2 columns. I am using dbCalc on the 2 fields and they
show up correctly on the report. It's just the variable that adds them that
is wrong.

procedure TfrmTrending.ppVarTotAvgCalc(Sender: TObject;
var Value: Variant);
begin
Value := ppDBCalcMinAvg.Value + ppDBCalcMinTAvg.Value;
end;

Delphi 5 Pro, RB 6.03.

--

Don Gollahon
gollahon@geneseo.net

Comments

  • edited March 2004
    Hi Don,

    When the DBCalc component is accumulating values to calculate an average, it
    stores the sum of the records in the Value property and the count of the
    records in the Divisor property. Then in the OnGetText event, it calculates
    the average using these two numbers. If you would like to add the two
    averages you can try converting the DBCalc.Text value to a Float or make the
    average calcluation on your own like the example below.

    Value := (ppDBCalcMinAvg.Value / ppDBCalcMinAvg.Divisor) +
    (ppDBCalcMinTAvg.Value / ppDBCalcMinTAvg.Divisor);

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.