# How to Add or subtract (+ or -) from subreport value to main report vale with condition in main report.

Hello Bosses

I am facing a problem in crystal repor would any one like to help me plzzz..

1) I have one main Report
2) I have another sub report

I want to Add(+) subreport value (Amount) to  main report.

in the main report i want to give condition (Condtional sum)

Like if mainreport.field.value='debit' then Add value from Subreport.filed.value +mainreport.filed.value

plz any problem in Qn. plz clarify me i will tell in details

My main problem is how add or subtract from subreport value to main report value with condition in main report.

LVL 2
###### Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x

Commented:

Formula - DeclVars
shared NumberVar Balance := 0.0;

In the subreport (subreport should be in the before the employee Name line and in that section.)

Formula - CalcBalance
shared NumberVar Balance;
Balance := {FieldInSubReportWithBalance};

In the Main detail section
Formula - MainBalance
shared NumberVar Balance;
Balance := Balance + {DebitField} - {CreditField};

May have to write it as
shared NumberVar Balance;
If isNull({DebitField} then
Balance := Balance - {CreditField};
else
Balance := Balance - {DebitField};

Balance

mlmcc

0

Commented:
You need to use shared variables to pass values between a report and its subreport.

In your subreport, create a formula that adds to a shared variable:
Whileprintingrecords;
shared numbervar Accumulate := Accumulate + {#RunningTotal};

In your main report create a formula that will display the global variable:
Whileprintingrecords;
shared numbervar Accumulate;

Hth,
Spykair.
0

Commented:
Also be sure to place the formula in the main report in a section *below* the section containing the subreport to ensure that correct values are displayed...

greetz,

Outin
0

Commented:

A further explanation of sharing data between main and subreports.

mlmcc
0

Commented:
1) are you only passing a single value from the sub-report to the main report? or multiple values? - i.e. do you only need to add the sub-report value once on the main report, or will you need an "accumulated" running total value there also?
2) is the Debit/Credit value stipulation only in the main report formula, or also true for a conditional sum in the sub-report (p.s. am an accountant, so please feel free to futher elaborate)
0

Author Commented:
The Format of the report is

Employe Name: XXXX           and his Opening BAlance   :2000 (This is Coming From Subreport)

Date        Entry Head      Entry Nature     Debit Amount    Credit Amount     Balance    Account  Remarks
9-Mar-05 TRAFFIC FINE     Debit               1000                                        3000(2000+1000)
15-Mar-05 TRAFFIC FINE   Credit                                    1000                  2000(3000-1000)
25-Mar-05 TRAFFIC FINE   Debit                                      500                   1500(2000-500)

So this type of Output User Wants.
1) Employee name and his Opening balances is coming fom Subreport
2)details is coming from Main report
3) to find out the Balance=from subreport opening balance + or - (Acc to debit and credit)
i m not able to find the Balances i required how to do plz help me if any one likes to. Further details i will Explain in details.
0

Commented: