Search code examples
crystal-reportscrystal-reports-2008

how do i sum data pulled out of a sub-report in crystal


I am able to pull a field out of the sub report with shared numbervar sub1Total; but I need to add them up at the end of group. If I try and do a sum on the field in the main report I get an error that that field can not be used with sum.


Solution

  • You can add up the values passed back from the subreport by keeping track of them via a global variable in the main report.

    //Initialize the variable in the Group Header of the main report
    whileprintingrecords;
    numbervar groupsub := 0;
    
    //Update the variable in the Details section of the main report
    whileprintingrecords;
    numbervar groupsub;
    shared numbervar subval;
    
    groupsub := groupsub + subval;
    
    //Print the accumulated group value in the Group Footer of the main report
    whileprintingrecords;
    numbervar groupsub;