0
votes

I am making a report using Crystal report. My column data(Amount) is grouped according to id(1 and 2). I want to print difference of total sum of amount according to id(1 and 2).

For eg:- In group id 1, amount field are:-
100
200
300

And in group id 2 amount fileds are:-
50
150
250

My output in crystal report should be: 1-2
i.e: (100+200+300) - (50+150+250)

Please help me. I have tried doing it through formula field in this way:-

local numbervar x=0;

if({Statement_of_Pay.Pay_Head_Type_Code}=1)
then
x:= x + {Statement_of_Pay.Amount}
else if({Statement_of_Pay.Pay_Head_Type_Code}=2)
then
x:= x - {Statement_of_Pay.Amount}

This is not working the way I want. Kindly help me!

1
where do you need the output to be displayed? and what is the problem with the above formula?Siva

1 Answers

0
votes

For summation you can use the sum option in crystal reports instead of writing a formula as you did.

Below solution works assuming group ID 1,2 are the results of the same group not 2 groups.

  1. Take the sum of the column by going to Right Click ---> Insert Summary and insert summary to the level you required.

  2. Create a formula @Group1

    whileprintingrecords;
    Shared NumberVar Storegroup1;
    if(GroupNumber=1)
     then
    Storegroup1:=sum({databasefield},{groupid});
    
  3. Create a formula @Group2

    whileprintingrecords;
    Shared NumberVar Storegroup2;
    if(GroupNumber=2)
    then
    Storegroup1:=sum({databasefield},{groupid});
    

now take the difference in the section you require. Create a formula @Display

EvaluateAfter(@Group1);
EvaluateAfter(@Group2);

Shared NumberVar Storegroup1;
Shared NumberVar Storegroup2;

Storegroup1-Storegroup2;