How to summarize a formula field in crystal reports?

元气小坏坏 提交于 2020-01-23 09:52:28

问题


How do I add a running total or summary field on a formula field in crystal reports?

// Sample Report

 Serial No.       Premium        Commission         Net (Premium-Commission)
-----------------------------------------------------------------------------
    1.              10               4                    6        
    2.              40              30                   10
  ---------------------------------------------------------------------------
  Grand Total       50              34                   16

In sample report, Net (Premium-Commission) is a formula field which gets evaluated for each row? How do I add a grand total/summary field for my formula? It seems we can add a summary field to only Command fields.


回答1:


Suppose Net (Premium-Commission) formula field name is {@Net}. Now you have to create another three formula fields.

  1. Initializer: this formula filed will be placed in header section to reset all variables.
  2. Increment: this formula field will be placed in detail section to summarize the value.
  3. Total: this formula field will be placed in footer section to show total of {@Net}.

Code will be writen in formula fields as below.

{@Initializer} WhilePrintingRecords; Numbervar dSum :=0;

{@Increment} WhilePrintingRecords; Numbervar dSum; //Don't initialize zero dSum:=dSum+{@Net}; //{@Net} formula field must be return numeric value

{@Total} WhilePrintingRecords; Numbervar dSum; //Don't initialize zero dSum;

Place all formula fields in their appropriate section and suppress {@Initializer} and {@Increment} formula field.




回答2:


If you are using any calculation then that is not possible but one workaround would be to sum the each row and reset it in header.

  1. Create a formula @Intialize in that write below code:

Shared NumberVar count; count:=0

  1. In detail write below formula and place it after Net (Premium-Commission).

Shared NumberVar count;

Count:=count+<>

\ 3. Now create one more formula @Display and place it in footer.

Shared NumberVar count; count;



来源:https://stackoverflow.com/questions/22779273/how-to-summarize-a-formula-field-in-crystal-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!