Create a running calculation by using the Report Writer (88667)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft FoxPro for MS-DOS 2.0
  • Microsoft FoxPro for MS-DOS 2.5
  • Microsoft FoxPro for MS-DOS 2.5a
  • Microsoft FoxPro for Windows 2.5
  • Microsoft FoxPro for Windows 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.

REFERENCES

"Interface Guide," version 2.0

Modification Type:MajorLast Reviewed:2/17/2005
Keywords:kbenv KB88667