Creating a Running Calculation Using the Report Writer

Last reviewed: April 29, 1996
Article 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, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5 and 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:

  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


Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.00 2.50 2.50a
KBCategory: kbenv kbprg
KBSubcategory: FxenvMemory


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.