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

Cumulative Sum in BeforePrint

edited August 2002 in General
I have a variable which keeps track of the cumulative sum of a
datafieldvalue.
I have the code for this cumulative sum calculation in the BeforePrint Event
for the GroupHeader where the variable component is located.

The report correctly calculates the cumulative sum for the first few records
on a page. However, when the end of the page is reached and the report
builder realizes that a record can not be placed on this page, the
cumulative sum is calculated again for this record but only for the next
page. Thus, the cumulative sum for the first record on each page subsequent
to the first page has the value of this record included twice in the
cumulative sum.

For example

DataValue being summed is Balance
Variable Component containing cumulative sum is Variable1

--------------------beginning of
page1---------------------------------------
Balance DatafieldValue Variable1.AsDouble

421,211 421,211 This
is correct
111,000 532,211 This
is correct
68,889 601,100 This
is correct
20,820 621,920 This
is correct
15,779 637,699 This
is correct
11,000 648,699 This
is correct
10,900 659,599 This
is correct
9,531 669,130 This
is correct
----------------end of page 1-------------------
--------------------beginning of
page2---------------------------------------
Balance DatafieldValue Variable1.AsDouble

8,878 686,886 This
is not correct

669,130 (from last record of page1) + 8,878 = 678,008

668,886 = 669,130 + 8,878 + 8,878

7,478 694,364
686,886 + 7,478 = 694,364

The cumulative sum is working, however, the base value (686,886

is not correct)

So on....

----------------end of page 2-------------------

I have tried putting the cumulative some as an Oncalc event with different
timings but still encountered the same problem.
Any suggestions are very much appreciated.

Thanks.
Prathy Kukkalli

Comments

  • edited August 2002
    Use a TppVariable and set its DataType to Double. The timing of the
    variable should be set to Traversal. You can set the variable to reset on a
    group if you have groups in the report. Use the reset on group start timing
    if you have a total in teh group footer. Use the variable's OnCalc event to
    calculate the value, and do not use the BeforePrint event. The OnCalc event
    is the only event in which you should use to calculate a value.


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited August 2002
    Thanks for the suggestions.
    Actually, I solved it by using the DBCalc component and selecting the
    datapipeline and calc type to sum. This gave me the cumulative sum and gave
    correct calculations for each page. It was in the Developer's Manual all
    along.

    Prathy

This discussion has been closed.