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

Sum and Region

edited October 2006 in General
I have a report with the detail in a region.
I need to print the total sum of two fields of the detail, in the
summary band of the master.
I placed a DbCalc connected to the detail datapipeline but seems that
the sum is not calculated correct

Comments

  • edited October 2006
    Hi Max,

    The proper way to calculate a sum inside the master report of a value in a
    subreport is to place an invisible TppVariable inside the detail band of the
    subreport and use its OnCalc event to update the value(s) of a TppVariable
    inside the Summary band of the master report. This way you get an accurate
    calculation as the detail dataset is traversed. Something like the
    following...

    procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant);
    begin
    //TotalVariable1 and 2 are in the Summary Band of the main report
    TotalVariable1.Value := TotalVariable1.Value +
    ppSubreport1.DataPipeline['Field1'];
    TotalVariable2.Value := TotalVariable2.Value +
    ppSubreport1.DataPipeline['Field2'];

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2006
    Maybe i forgot to mention some important informations .. sorry

    My report has a group and for every record in the master, print the
    detail in a REGION.
    Your solution does not resolve the problem, i tried to put a DbCalc in
    the detail to sum the value of the field, but the value is reset when
    the master record changes.
    If it was possible to not reset the value i think it should be enough
    copy the last value of the DbCalc on a Label on the summay band of the
    master
  • edited October 2006
    Hi Max,

    Please read my previous post again. Do not use DBCalc components, use
    Variable components and make the calculation manually in the OnCalc event of
    the variable inside the detail band of the detail subreport.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2006
    I did what you said using a variable, but i can't solve the problem

    this is an extract of my report

    Value

    Group 1
    Rec#1 0
    Rec#2 179,88
    Rec#3 1

    // now the total is 180,88 OK !

    Group 2
    Rec#1 0
    Rec#2 5,16

    // now the total is 5,16 Error, it should be 186,04 the sum of
    all records
  • edited October 2006
    Hi Max,

    Variables will not reset unless you tell them to using the ResetType
    property. Are you certain the ResetType is set to ReportEnd (which is the
    default)? Note that you will need to use multiple variables to successfully
    get this working.

    I created a simple example that shows what I mean.

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

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2006
    Thank you .. but i'm using RAP not delphi event ... how to access to
    the variable in the master report from the subreport ?
  • edited October 2006
    Hi Max,

    For future reference, please post RAP questions to the RAP newsgroup. This
    helps us understand what you are using and allows us to give you a more
    accurate answer faster.

    For RAP, you will need to take a slightly different approach. You will need
    to create a global TppVariable in the main report and assign it to the
    TppVariable that will hold the actual value. Then you will use the OnCalc
    event of a TppVariable in the subreport to update the value of the global
    variable (effectively updating the value of the TppVariable in the main
    report as well). Take a look at the following demo for an example of this.

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

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

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