Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula field = parent field + subreport field Post Reply Post New Topic
Author Message
desgordon
Newbie
Newbie
Avatar

Joined: 11 May 2010
Location: Belize
Online Status: Offline
Posts: 3
Quote desgordon Replybullet Topic: Formula field = parent field + subreport field
     Posted: 11 May 2010 at 12:27pm
Is it possible to create a formula field that sums a parent report field with a subreport field and if so how?

I am doing a payroll report.  I do a selection of all transactions that are wages transactions i.e. transaction type in (list of wages transaction types) and do this in my main report.  In the subreport I do the same thing for allowances transactions, because I couldn't very well select these in the same query that I select the wages transactions.  The reason I need to differentiate between them is that social security contributions are payable on wages and the amount of the contribution depends on the amount of the wages.  Now after taking out the social security contribution I want to sum the total that is payable to the employee.  

That is why I need to sum the allowances field in the subreport with the wages - ss contribution  field in the main report.

Th subreport is positioned in the detail column of my main report.

If its not possible to sum the fields in question, is there a better way of achieving my desired result in crystal reports?

Please for some help on this.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 11 May 2010 at 6:25pm
The way to share variables between the main report and the subreport is to create a formula in both the main report and subreport and declare the same shared variable in both formulas. Then they will share their data.

For example,
Shared NumberVar TxTotal;

Then in the formulas summarize the data appropriately.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
desgordon
Newbie
Newbie
Avatar

Joined: 11 May 2010
Location: Belize
Online Status: Offline
Posts: 3
Quote desgordon Replybullet Posted: 12 May 2010 at 3:43am
Thanks Brian.  I am new to this therefore it may take me a while to implement your suggestions.  I might need some more help to do so.  Will get back to you.

And I will definitely purchase a copy of the encyclopedia today.
IP IP Logged
desgordon
Newbie
Newbie
Avatar

Joined: 11 May 2010
Location: Belize
Online Status: Offline
Posts: 3
Quote desgordon Replybullet Posted: 17 May 2010 at 1:24pm
This is what I did:

Create two separate reports WagesReport.rpt which sums up all wages transations for each employee and AllowancesReport.rpt which sums up all allowance transactions for each employee.

I include AllowancesReport as a subreport of WagesReport and place the allowances total in the details section along with the wages total name etc. fields.

My report now looks like the following, which is fine:

      Name
First         Last  SSN    Bank  Account#  Wages  SS     Allowances
John        Jones1234  Scotia 22-333     230.00  9.00  400.00   

I proceeded to add the column GrossPay which is the sum of Wages + Allowances.  While editing WagesReport I right click on the Allowance subreport and   select the edit subreport option.  I then create a new formula field called frmAllowances and in the formula editor I type the following:

Shared NumberVar shrAllowances;
shrAllowances := {ALLOWANCES.ALLOWANCES};

{ALLOWANCES.ALLOWANCES} is the field that represents the total allowances.

I save the subreport.

I then edit WagesReport by creating a new formula field called GrossPay which is supposed to sum up the wage amount and allowance amount.  In the formula editor I type the following formula for GrossPay:

Shared NumberVar shrAllowances;
{WAGES.WAGES} + shrAllowances;

I insert GrossPay in the details section of my report and expect to get the following:

Name
First         Last  SSN    Bank  Account#  Wages  SS     Allowances Gross Pay
John        Jones1234  Scotia 22-333     230.00  9.00  400.00        630.00

Instead I get this:

Name
First         Last  SSN    Bank  Account#  Wages  SS     Allowances Gross Pay
John        Jones1234  Scotia 22-333     230.00  9.00  400.00        230.00

Where have I gone wrong?
IP IP Logged
Debbie Giles
Newbie
Newbie
Avatar

Joined: 16 May 2008
Online Status: Offline
Posts: 10
Quote Debbie Giles Replybullet Posted: 17 Oct 2010 at 10:17pm
Did you get this right?  Debbie
Debbie Giles
Syspro Consultant
EOH
+27 21 525 7200
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum