Get sum of a field per page in crystal report

一个人想着一个人 提交于 2019-12-12 02:47:27

问题


I Have a Crystal Report and get the sum of a field like this:

Sum({TheField})

and I put it in PageFooter section to have it in all pages but if the report has multiple pages it shows the sum of all fields and I need to get the sum per page.

Any ideas how to do that?


回答1:


You can get page level totals as follows. Create three formula fields in report design, namely ff_Reset_Total, ff_Current_Total, ff_Add_Record and set their values in formula editor as under:

  1. ff_Reset_Total

    whileprintingrecords;
    numbervar PageTotl;
    PageTotl:=0;
    
  2. ff_Current_Total

    whileprintingrecords;
    numbervar PageTotl;
    PageTotl;
    
  3. ff_Add_Record

    whileprintingrecords;
    numbervar PageTotl;
    PageTotl:=PageTotl + {TheField};
    

Now place these formula fields in your report as under:

  1. ff_Reset_Total in Page Header Section
  2. ff_Current_Total in Page Footer Section
  3. ff_Add_Record in your Details Section

Now hide ff_Reset_Total and ff_Add_Record by Right Click on each of them in Page Header and Details Sections, point to Format Field and then in the Common tab select Suppress




回答2:


Create a variable in the report header.

numbervar runningtot;
runningtot:=0;

Add {TheField} to the variable on line level.

numbervar runningtot;
runningtot:=runningtot+{TheField};

Display the variable in the page footer A

numbervar runningtot;
runningtot;

Reset the variable to zero in page footer B

numbervar runningtot;
runningtot:=0;

You could display and reset the variable in one formula in page footer A, but the above is easier to digest..



来源:https://stackoverflow.com/questions/33507655/get-sum-of-a-field-per-page-in-crystal-report

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