I do use groups already, but the formula is being applied at the details line.
I am thinking the best way to do this is with a For loop but I cannot write one and I was hoping people could help me.

My original fomula is this:

If {@Display Selection} = "Display" then
if {AFACCOUNT.AFACCURBALINT} >= 0 then
{AFSPLIT.AFSPAMT}*(-1)
else
({AFSPLIT.AFSPAMT}-{AFACCOUNT.AFACCURBALINT})*(-1)
else
0.00
----------------------
{@Display Selection} is a formula that evaluates each financial transaction to determine if it should be Displayed on the report or Not-Displayed based on date ranges and transaction type. This works fine.

{AFACCOUNT.AFACCURBALINT} is where we store the accounts current balance with interest. Despute appearing in our system as a positive number, it is really a negative number (it is money owed to us)

{AFSPLIT.AFSPAMT} is where we store the payment amount. It appears in a negative value to subtract from the {AFACCOUNT.AFACCURBALINT} but is in fact a positive number.

{ARACCONT.ARACID} is the unique customer identifier.

{AFTRANSACTION.TRKEY} is the unique transaction ID (each payment for {AFSPLIT.AFSPAMT} has a unique TRKEY)

------------------------

What I am thinking the best way to do this, if its possible is this.

A For loop that counts the number of times the {ARACCONT.ARACID} appears in the crystal report.

It then selects the *last* payment which will also have the highest {AFTRANSACTION.TRKEY} . I don't know if you can just say to select the last payment or if you would need something to relate to, which could be the {AFTRANSACTION.TRKEY}.

Once that is selected then it would apply the following formula.

If {@Display Selection} = "Display" then
if {AFACCOUNT.AFACCURBALINT} >= 0 then
{AFSPLIT.AFSPAMT}*(-1)
else
({AFSPLIT.AFSPAMT}-{AFACCOUNT.AFACCURBALINT})*(-1)
else
0.00

all else transactions would display the following:

If {@Display Selection} = "Display" then
{AFSPLIT.AFSPAMT}*(-1)
else
0.00

------------------

Can someone help me write this report? It would be greatly appreciated and help me save what little hair I have left?