Arsalan
Arsalan

Reputation: 744

Get sum of a field per page in crystal report

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?

Upvotes: 0

Views: 15222

Answers (2)

haraman
haraman

Reputation: 2742

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

Upvotes: 2

vice
vice

Reputation: 605

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..

Upvotes: 0

Related Questions