Microsoft KB Archive/88667

= Create a running calculation by using the Report Writer =

Article ID: 88667

Article Last Modified on 2/17/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a

-



This article was previously published under Q88667



SUMMARY
You may want to create a running calculation in a report that will update after each grouping and total the result.



MORE INFORMATION
For example, suppose your database is called TEST.DBF. In this database are fields called QTY and ITEMNO. For this example, you want to group on ITEMNO and track the totals in QTY for each item number. You then want to track the totals in QTY as a running calculation within each group and display a grand total at the end of the report. Do the following:
 * 1) Create your grouping on ITEMNO.
 * 2) Choose Report from the menu bar, then select Memory Variable. Choose Add and create a variable X that will be reset at the end of the group ITEMNO. X is the expression SUM(QTY) and has an initial value of 0.
 * 3) Choose Add again and create a second variable called Y. Y also has an initial value of 0 and is the expression X+Y. Y is reset at the end of the report.
 * 4) Place the cursor in the report group footer. Choose Report from the menu bar to place the calculations in your report. Select Field from the list.
 * 5) Choose X as the value of the group's calculation and choose Y as the field for your running calculation.

Each time the group changes, the sum of QTY will be contained in the variable X and Y will add that value to its own value. Because Y is reset only at the end of the report, Y will keep a running calculation of each time the value of X changes.

