Search code examples
crystal-reports

Sum Running Total in Crystal Report


I created a running total for my report, we will named it RT1. Now i created again another running total to get the sum of RT1 but i get the wrong answer. Any advice on how to correctly do this?

I have this formula in my first Running Total
//Formula1

@SpTotalReset
WhilePrintingRecords;
numbervar sp := 0;
//I placed it in my GroupHeader Date

//Formula2

@SpRunningTotal
WhilePrintingRecords;
numbervar sp;
sp := sp + {Sec/Pc};
//I placed it in my Details

//Formula3

@SpTotalDisplay
WhilePrintingRecords;
numbervar sp;
//I placed it in my GroupFooter Date

This is the formulas of my second running total
//Formula1

@MoTotalReset
WhilePrintingRecords;
numbervar mo := 0;
//I placed it in my GroupHeader Date

//Formula2

@MoRunningTotal
WhilePrintingRecords;
numbervar mo;
mo := mo + {@SpTotalDisplay};
//I placed it in my GroupFooter Date beside @SpTotalDisplay

//Formula3

@MoTotalDisplay
WhilePrintingRecords;
numbervar mo;
//I placed it in my GroupFooter Name

Solution

  • Change like this:

    @MoTotalReset

    WhilePrintingRecords;
    Shared numbervar mo := 0;
    //I placed it in my GroupHeader Name
    

    And apply shared for all formulas. This should work.