How to Use a UDF to Calculate Percentages in a Report

ID: Q132727

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, version 2.6a

SUMMARY

To calculate percentages of a group total in report using the Report Writer, you must create a UDF (user defined function).

MORE INFORMATION

The FoxPro Report Writer calculates totals in a top down manner. To get a detail item's percentage of a total that resides in the group footer band, the total must first be calculated in the group header. This can be accomplished by using the following code in a UDF:

   SET TALK OFF
   PUBLIC msum     && initialize variable for sum total
   msum=0
   y=RECNO()       && store record number to variable so total from
   * previous group is not added on
   x=<field name>  && store field which is grouped to variable
   SUM <numeric field name> FOR  x=<field name> TO msum
   GO y
   RETURN msum     && this will simply display the total in the group
   * header that appears in the group footer

For more information about UDFs, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q113754
   TITLE     : "Syntax Error" When Verifying UDF() in Report Writer

Additional reference words: 3.00 VFoxWin KBCategory: kbtool kbcode KBSubcategory: FxtoolRwriter


Last Reviewed: July 31, 1995
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.