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

Running Total

edited April 2005 in RAP
Hi,

It seems simple enough if I want to do a total of a database field in
RBuilder. I use the DBCalc field and it works like a dream. However, In
Crystal, I could do totals for other fields.

Example: Im using a Variable field to accumulate total. Can I not then just
do a Sum of that Variable? It seems a very tedious way of doing it, unless
im attempting it the wrong way?


Sample:

RepCode (GroupHeaderBand)
Analysis Code (GroupHeaderBand)
Category Code (GroupHeaderBand)
DETAILS variable1 (variable1 = qty * width)
Category Code (GroupFooter) SHOW Total of variable1
(CategoryTotal)
Analysis Code (GroupFooter) SHOW Total of variable1 (AnalysisTotal)
RepCode (GroupFooter) SHOW Total of variable1 (RepsTotal)



There could be n Reps, and n Analysis and n Categories....the totals have
also to be set to zero on any group changes...


Thanks in advance...

Comments

  • edited April 2005
    Hi Tarun,

    I would recommend creating two TppVariable components. Place one in your
    detail band and in its OnCalc event update the value of the other
    TppVariable with the calculated sum you want to display. Then you can use
    the Timing dialog (from the variable's popup menu) to determine when you
    would like it to reset its value. See the following article on making
    calculations in ReportBuilder.

    ----------------------------------------------------------------------
    TECH TIP: Performing Calculations
    ----------------------------------------------------------------------

    Calculations can be done either on the data access side
    or within ReportBuilder.

    When designing reports there are always decisions to be made as to
    how much processing to do on the data side versus the report side.
    Usually doing more on one side can greatly simplify the other. So it is
    often a personal choice based on the power and flexibility of the data
    and report tools being used.


    DataAccess
    ----------

    a. Use SQL - using SQL you can perform many common calculations:

    example: Select FirstName + ' ' + LastName As FullName,
    Quantity * Price AS Cost,


    b. Delphi TDataSets enable you to create a calculated TField object
    and use the DataSet.OnCalcFields event

    c. Perform any amount of data processing, summarizing, massaging
    etc. to build a result set (query or temp table) to feed to the report.


    ReportBuilder
    -------------

    Calculations in ReportBuilder are performed primarily using
    the TppVariable component.

    a. Set the Variable.DataType

    b. Code the calculations using the Variable.OnCalc event.

    c. Use the Timing dialog to control the timing of the OnCalc event.
    To access the Timing dialog, right click over the Variable
    component and select the Timing... option from the speed menu.

    d. Set the LookAhead property to True, when you need to display
    summary calculations in the title, header, group header, etc.

    e. To perform calculations based on the results of other
    calculations use the Calc Order dialog of the band. To access
    the Calc Order dialog, right click over the Band component
    and select the Calc Order... option from the speed menu.


    By using TppVariable components ReportBuilder will take care of caching
    intermediate results of accumlated calcs that cross pages.

    There are a number of calculation examples in the main demos.dpr
    project.

    ---

    Additional Notes:

    1. Do NOT use Band.BeforePrint or Band.AfterPrint. These events fire
    multiple times and therefore should not be used for calculations.

    2. Do NOT store results in variables that exist outside of the reports.
    For example - form level variables.


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2005
    Hi Tarun,

    Nico is right, use two TppVariables.

    I had the same problem the first time I used ReportBuilder. Also, there are
    some functions in Crystal's Running Total field that can't be reproduced
    easily in ReportBuilder, like the DISTINCT COUNT of a variable. I found a
    way to do this that works well. I also built a Crystal to RB converter that
    eased my conversion, so if you have any questions regarding on HOW-TO-DO
    some special features, feel free to ask me.

    David
This discussion has been closed.