Reputation: 1
I have 3 columns in my details section:
I want my formula field total to subtract the value if the type is debit and add the value when it is credit. The logic would look like this in C++. How can I rewrite this in Crystal syntax?
if(type=="credit")
total = total+balance
else if((type=="credit")
total = total-balance;
Upvotes: 0
Views: 126
Reputation: 3680
Try creating a formula field called UpdatedTotal
and input the following code:
If {type} = "debit" Then
{total} - {balance}
Else If {type} = "credit" Then
{total} + {balance}
Then just drop the formula field into the report wherever you want it to display.
In Crystal it's not necessary to assign the updated total value: This new field automatically displays the updated total and can be used in other calculations by referencing {@UpdatedTotal}
by name.
Upvotes: 0
Reputation: 590
You can try this for crystal report formula
If {type} = "credit" Then
{total} := {total} + {balance}
Else If {type} = "debit" Then
{total} := {total} - {balance}
Alternately you can write case statement in sql query
to get updated_total
SELECT type, total,balance.....,
CASE
WHEN type ="credit" THEN (total + balance)
WHEN type ="debit" THEN (total - balance)
END as updated_total
FROM Datatable ;
Upvotes: 1