Last Value of previous record!

Trying to build a report which calculates accumulated/compound interest for our company but having problems.
Row 1:

PeriodStart PeriodEnd CurrentContribution Type Rate Int.Credit Closing Bal.
01/01/07 28/02/07 1517.15 A 0.32 40.46 1557.61

Row 2:
PeriodStart PeriodEnd CurrentContribution Type Rate Int.Credit Closing Bal.
01/03/07 31/05/07 3030.00 B 0.16 60 3090.60

Now I want to pick the Closing Balance of Row 1 and calculate its interest for the second row as it should be carried forward.

To be more explicit I want to to be able to calculate the interest of the previous period on the current period.

Any ideas how I can do this please…?

Thanks.

Hi,

I’m not quite sure I fully understand what You want to do.

But, it sounds to me like it could be obtained by defining a Global Variable of datatype = decimal.
(PriorPeriodInterest - Decimal)

As the very last thing in the OnAfterGetRecord-trigger, You set the variable to the interest-value You just calculated.
This way, for all the other processing on the trigger, the variable vil have the same value as the interest calculated on the last record.

regards,

Alexander

By the by I have being able to get the previous record I want. This is how I do it: created an “Entry No.” in the table as integer and auto-increment and use the code below:

EntryNo := “Entry No.” -1;
BenefitsKey.SETRANGE(“Entry No.”,EntryNo);
BenefitsKey.SETRANGE(“Employee #”,Cont.“Employee No.”);

IF BenefitsKey.FIND(’-’)
THEN BEGIN
OpeningBalance := BenefitsKey.ClosingBalance;
END;

Its working perfect and calculating properly. The only problem I have now is the automated calculation only works On Modify Trigger and not after validating the last insert field.
Below is the whole code for reference:

Cont.SETRANGE(“Employee No.”,“Employee #”);
Cont.SETRANGE(“From Date”,“Period Start”,“Period End”);
Cont.SETFILTER(“From Date”,’>=%1’,“Period Start”);
Cont.SETFILTER(“To Date”,’<=%1’,“Period End”);

//Code to Count Months
IF (“Period Start” <> 0D) AND (“Period End” > “Period Start”) THEN BEGIN
Calendar.RESET;
Calendar.SETRANGE(“Period Type”,Calendar.“Period Type”::Month);
Calendar.SETRANGE(“Period Start”,“Period Start”,“Period End”);
Months := Calendar.COUNT;
END ELSE
Months := 0;
// Code Ends above.

IF Cont.FIND(’-’)
THEN BEGIN
TotalAmount := Cont.Quantity;
IF Cont.NEXT <> 0
THEN
REPEAT
TotalAmount := TotalAmount + Cont.Quantity;
UNTIL Cont.NEXT = 0;
END;

IntCredit := (TotalAmount * Rate * Months)/24;
CurrAccTotal := IntCredit + TotalAmount;

EntryNo := “Entry No.” -1;
BenefitsKey.SETRANGE(“Entry No.”,EntryNo);
BenefitsKey.SETRANGE(“Employee #”,Cont.“Employee No.”);

IF BenefitsKey.FIND(’-’)
THEN BEGIN
OpeningBalance := BenefitsKey.ClosingBalance;
END;

OpIntCredit := OpeningBalance * Rate;
ClosingBalance := OpIntCredit + OpeningBalance + CurrAccTotal;

Any ideas welcome Please!