问题
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:
ff_Reset_Total
whileprintingrecords; numbervar PageTotl; PageTotl:=0;
ff_Current_Total
whileprintingrecords; numbervar PageTotl; PageTotl;
ff_Add_Record
whileprintingrecords; numbervar PageTotl; PageTotl:=PageTotl + {TheField};
Now place these formula fields in your report as under:
ff_Reset_Total
in Page Header Sectionff_Current_Total
in Page Footer Sectionff_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