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

Problems with calculate Grand Totals in Report

edited September 2002 in Subreports
Hi !

I have a problem with calculate totals in report.
I attached small examples with this problem.
What did I make incorrect ?

Thanks.
Roman Koval.

Comments

  • edited September 2002
    Only use TppVariables and their OnCalc event handlers for all calculations.
    Do not use the generation events of the bands as they may fire more than
    once when the band tries to fit on a page but can't so it has to regenerate
    on the next page.


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited September 2002
    I am using TppVariables and OnCalc events.
    Please look at examples in attachment.
    There is grand total calculated in OnCalc event handler (in RAP code) and
    control grand total calculated in SummaryBeforeGenerate
    ( in Delphi code).
    Those totals are defferent.

    Thanks.

  • edited September 2002
    Don't use SummaryBeforeGenerate for any calculations, or any other event
    than TppVariable.OnCalc. Only use TppVariables and TppDBCalcs for
    calculations. Do not store calculation values inside of Delphi variables.


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited September 2002
    Jim !

    I calculated totals in BeforeGenerateSummary like this:

    procedure TForm1.ppSummaryBand1BeforeGenerate(Sender: TObject);
    begin
    vCSumOfAmount.AsDouble := 0;
    vCSumOfTotal.AsDouble := 0;

    tblCustomers.First;
    while not tblCustomers.Eof do
    begin
    while not tblOrders.Eof do
    begin
    vCSumOfAmount.AsDouble :=
    tblOrders.FieldByName('AmountPaid').AsFloat + Amount.AsDouble;
    vCSumOfTotal.AsDouble := tblOrders.FieldByName('ItemsTotal').AsFloat
    + vCSumOfTotal.AsDouble;
    tblOrders.Next;
    end;
    tblCustomers.Next;
    end;
    end;

    And this result is correct.

    But, if I use TppVariables OnCalc event handlers - result is incorrect.
    Maybe you don't understand my problem.
    Can you see samples in attachment at last.

    Thanks.
    Roman Koval.



  • edited September 2002
    Sorry, I misunderstood. You can't sum using DBCalcs in the main report over
    a subreport connected to a detail dataset. Here is an example which shows
    how to use variables inside the subreport to calculate the correct number of
    times (once for each detail record) and then update variable values in the
    main report's summary band as it calculates:

    http://www.digital-metaphors.com/tips/SubreportTotalsInMainSummary.zip

    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited September 2002
    Hi, Jim !

    Thanks for example.
    But if I changed property ppSubReport1.KeepTogether := True report was
    generating incorrect.
    Try it.

    Roman K.

  • edited September 2002
    That is the behavior I get as well in this tip. We'll have to modify the
    project to cache the calculations as an added feature.


    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.