Skip to Content
0
Former Member
Dec 06, 2011 at 02:12 AM

Using Global Variables to Compute Running Total Comparisons

209 Views

Hello,

I am trying to create a formula for calculating the percentage difference between two running totals. In my report, I have grouped months by Quarter and have created a running total for each quarter. What I need to do now is to add a row for comparing the totals of each quarter using the following formuls:

(Current Quarter - Previous Quarter)/Previous Quarter

Anyway, I was looking at using global variables in order to achieve this. The Crystal Reports formula I have is below. However, when I try to save it I get the following message:

The remaining text does not appear to be part of the formula ( everything after the IF statements is highllighted )

Basically, my goal is to use a global variable to store the previous groups running total in order to calculate the comparisons I need. I was just wondering if this is the correct way to achieve what I need to do or is there a better way? Also, would appreciate any help in fixing the formula posted below.

thanks

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

WhileReadingRecords;

Global NumberVar previousTotal;

previousTotal := 0

if ( previousTotal > 0 )

then

({#Quarter Total} - previousTotal)/previousTotal

else

0

previousTotal :={#Quarter Total}