I am writing a report that will calculate the Month-to-Date, Quarter-to-Date and Year-to-Date expenses for a department. Our fiscal year runs from July 1 to June 30. The database stores the period of the transaction (ie: July would be period 1, August – period 2, etc.) so this can be used in the calculation. I thought I could use the Sum(fld, condFld, cond) to calculate this amount, but when I check it, Crystal says it “cannot calculate running total.” Below is code I wrote to calculate the amount for Quarter to Date.
I am fairly new to Crystal and would appreciate any advice on using the Sum function or suggestions for a different way to calculate this.
Thanks,
michele
Code:
numbervar CurrentMonth := Month (today);
numbervar CurrentPeriod;
currencyvar QuartertoDate;
//calculate period I am in
if CurrentMonth = 7 then
CurrentPeriod := 1
else if CurrentMonth = 8 then
CurrentPeriod := 2
else if CurrentMonth = 9 then
CurrentPeriod := 3
else if CurrentMonth = 10 then
CurrentPeriod := 4
else if CurrentMonth = 11 then
CurrentPeriod := 5
else if CurrentMonth = 12 then
CurrentPeriod := 6
else if CurrentMonth = 1 then
CurrentPeriod := 7
else if CurrentMonth = 2 then
CurrentPeriod := 8
else if CurrentMonth = 3 then
CurrentPeriod := 9
else if CurrentMonth = 4 then
CurrentPeriod := 10
else if CurrentMonth = 5 then
CurrentPeriod := 11
else if CurrentMonth = 6 then
CurrentPeriod := 12;
//calculate what month in the quarter I am in
if (CurrentMonth mod 3) = 1 then
//QTD is only current month
QuartertoDate := Sum ({tfgld106.amnt},{tfgld106.rprd}, CurrentPeriod);
I am fairly new to Crystal and would appreciate any advice on using the Sum function or suggestions for a different way to calculate this.
Thanks,
michele