Related Information Examples & Tutorials

How To Use Totals In Reports

This topic discusses the use of totals in reports.

Requirements

- Familiarity with use of the Report Writer in Collect!
- Understanding of how to use loops in reports.

Top of page.

Overview

By default, Collect!'s report system calculates and prints Totals of all numeric fields when you produce a list using the loop structure. You can inhibit this automatic totaling with the NO TOTAL command at the beginning of your loop.

tip.gif Disabling totals allows you to create your own totals. Try using the built-in features first. They may be all you need.

Please refer to How To Print A List Of Records to understand the basic concepts for building loops.

Top of page.

No Total - Active Accounts

This report snippet prints all active accounts for the currently selected Client, and does not print the total owing for all printed Debtors at the bottom of the list.

@cl.de NO TOTAL WHERE (@de.mo = Active)
@de.na @de.fi @de.ow
@cl.de

Top of page.

Totals - Active Accounts

To print totals in the above example, simply leave out the words NO TOTAL and Collect! will total and print the Owing amounts.

@cl.de WHERE (@de.mo = Active)
@de.na @de.fi @de.ow
@cl.de

Top of page.

Totals - Transactions

A more complicated scenario is explained in the following report snippet. This code will print all active accounts for the currently selected Client, list all transactions for each active account, and print the totals for all transactions printed.

@cl.de WHERE (@de.sta = ACT)
@de.na @de.fi @de.ow
@de.tr NO TOTAL
@tr.pd @tr.ty @tr.tu @tr.di @tr.co
@de.tr
@cl.de

This example is interesting because it uses NO TOTAL in the transactions loop. This creates a list of all transactions for each active account, but does not total the amounts listed in To Us and Direct payments. However, the "outer" loop, through the Client's debtors, does not have a NO TOTAL condition placed on it. Therefore, at the end of this loop, the report system totals all the amounts listed. This shows that with very little extra code, you can produce reports quickly with totals because of the built-in functionality of the Report Writer.

Top of page.

Totals Only, No Detail

The SUM command in report loops lets you print the sums of a list only. You can also print the count, but be aware that the count @n is only valid within the loop. We will examine these concepts now.

Top of page.

Sum And Where In Totals

This example prints the number of transactions and the sum of the "To Us", "Direct" and " Commission" amounts for active Debtors only.

@de WHERE (@de.mo = Active)
@de.tr SUM
@n @de.na @tr.tu @tr.di @tr.ca<
@de.tr
@de

The line @de.tr SUM prints only the total of all transactions, not all transaction details. At the end of the list, all amounts are totaled, including a total count of all records listed.

@n numbers the records as they are listed.
See How To Number Pages and Records for more tips about using this control code. A total number is tallied automatically and printed at the end of the list with the other totals.

Top of page.

Totals Using Math

You can use math to add amounts in your own ways if you do not want to use the automatic totals shown in the above examples. Sometimes this is necessary for more complex needs, but try the simplest solutions first. They may work for you. Please see How To Use Static Variables for more information on using variables to total amounts in your reports.

Top of page.

See Also

- How To Use Static Variables
- How To Number Pages And Records
- Report Sample to view sample reports and letters
- Report Topics Index for a list of all report and letter topics

Top of page.

Was this page helpful? Do you have any comments on this document? Can we make it better? If so how may we improve this page.

Please click this link to send us your comments: helpinfo@collect.org