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

Custom group totals

edited August 2003 in General
Hi,

if i have two TppDBPipeline components bind in a master-detail ralationship
(with MasterDataPipeline and MasterFieldLinks), is it possible to traverse
all the detail records that belong to the current record in the master
pipeline?

I need to know that to solve the following problem. In the detail table i
have a field which contains the amount to pay (tax included) and the tax
rate for this amount. In the group footer i have to display sums for:
1) sum of all the "amount to pay" fields excluded the tax -> the "Without
tax" in the example below
2) sum of tax rate 8,5%
3) sum of tax rate 20%


Example (i'll show only the detail records without the master):

ID Amount to pay Without tax Tax amount Tax rate
1 120 100 20 20%
2 240 200 40 20%
3 108,5 100 8,5 8,5%
4 500 500 0 0%


Totals:
1) sum of Without tax: 900
2) sum for tax rate 8,5%: 8,5
3) sum for tax rate 20%: 60 (=20+40)


(As you can see i haven't the sum for the tax rate 0% - because it's 0).

The first problem i encountered here is that the report should be flexible
enough to calculate any number of tax rates (so if the detail records had
only 8,5% tax rates, i should write only sums for 1) and 2) ), so i thought
to use a memo. I'm, explaining this only if it helps you to give a more
precise suggestion.

The biggest problem is how to calculate those sums. I thought to use a
dynamic table in Delphi (becuse i can have many tax rates).
If i could traverse all the detail records(for a given master record), i
could simply calculate the sums. On the other hand, it's maybe faster to
calculate those sums as the report's pipeline traverses the data, but i
don't know when to calculate (on which event - maybe on the data pipelane
traversal) and when to reset the table (again on which event).

When displaying those fields in the report i calculate them in the
BeforeGenerate event of the detail band - is it possible to calculate the
sums there?

I'm sure that there should be a simpler solution than using dynamic tables
in delphi.

Any suggestions on how to (simpler) solve this problem? Is there any similar
example/tutorial?

Thanx

Comments

  • edited August 2003
    Hello,

    You should be able to get the results you need by using TppVariable
    components to calculate the sums you need. Below is a small example of how
    you might do this. Essentially you would be placing a single TppVariable in
    the detail band and in it's OnCalc event, update three other TppVariable
    components with the correct sums of the current dataset field values. Hope
    this helps.

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

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003

    how
    in
    Hope

    Hi,

    that's a good idea. But what if i have to calculate more (or less) than 3
    different values (as shown in the example) - maybe not in this specific case
    (with taxes) but in a different kind of report? So, i should be able to
    calculate as much different sums as there are different values of a field.

    Thanx
  • edited September 2003
    Hi,

    Yes, you would be able to calculate as many different sums as you like from
    the TppVariable.OnCalc event. You should be able to calculate the sum
    without tax, sum with 8% tax, and sum with 20% tax all in the same event.

    --
    Best Regards,

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