#### To create running totals using a formula

1. Create a report using the sample data, `Xtreme.mdb` located in the `File Data Sources` folder of the Data Explorer dialog box. Link the Customers and Orders tables and place the following fields from left to right in the Details section:

    {customer.CUSTOMER NAME}
    {orders.ORDER ID}
    {orders.ORDER AMOUNT}

1. On the `Insert` menu, click `Formula Field` then double-click `Formula Fields` in the Field Explorer dialog box.
2. Name the formula @RunningTotal and click `OK`.
3. Enter the following into the Formula Editor:

    WhilePrintingRecords;
    CurrencyVar Amount;
    Amount := Amount + {orders.ORDER AMOUNT};

1. Click `Save and Close`.
2. Place this formula in the Details section of your report, just to the right of the {orders.ORDER AMOUNT} field.

   This formula prints the running total of the values in the Order Amount field.

3. On the `Insert` menu, click `Group` and group the report on the {customer.CUSTOMER NAME} field.
4. In the Formula Editor, create @AmountReset:

    WhilePrintingRecords;
    CurrencyVar Amount := 0;
    This formula says:Set the value in the Amount variable to 0.

1. Place this formula in the Group Header #1 section of your report.

   Because the Group Header #1 section appears once for every group, @AmountReset will execute each time the group changes. Thus, the Amount variable is reset to 0 each time a new group begins.

2. Select the @AmountReset formula on the report and use the Format Editor to suppress it so that it will not appear in the final print-out.
3. In the Formula Editor, create @AmountDisplay:

    WhilePrintingRecords;
    CurrencyVar Amount;
    This formula simply displays the current value of the Amount variable at any time.

1. Place this formula in the Group Footer #1 section of your report.

   Because the Group Footer #1 section appears once for every group, @AmountDisplay will execute each time a group ends. Thus, the value stored in the Amount variable will be printed each time the group changes.

Note: This formula prints the same value that @RunningTotal prints as the running total for the last record in each group. But since it is printing it in the Group Footer section, it acts as a group subtotal, not as a running total.

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com