Creating a Running Calculation Using the Report Writer
ID: Q88667
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, version 3.0
-
Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a
-
Microsoft FoxPro for Windows, versions 2.5, 2.5a
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:
- Create your grouping on ITEMNO.
- 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.
- 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.
- 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.
- 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.
REFERENCES
"Interface Guide," version 2.0
Additional query words:
VFoxWin FoxDos FoxWin
Keywords : kbenv FxenvMemory
Version : MS-DOS:2.0,2.5,2.5a; WINDOWS:2.5,2.5a,3.0
Platform : MS-DOS WINDOWS
Issue type :