Crystal Reports - subreport contains value I need to include in mathematical formula

I'm changing an invoice report to include a subreport that displays past due invoices in a group footer.  

How can I access and take advantage of the subreport invoice_balance values for any rows that get included in the main report.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

By declaring a shared variable in the subreport and then storing the invoice total in the shared variable, you can then access the invoice total from the main report.

1. In the subreport, create a formula similar to the one below:
//Stores the grand total of  the  
//{Orders.Order Amount} field  
//in a currency variable called 'myTotal'  
Shared CurrencyVar myTotal := Sum ({Orders.Order Amount})

Open in new window

Put this formula in a section below all the detail sections such as the report footer.

2. Place this formula in your subreport.

3. In the main report, create a formula that declares the same
variable name:
//Returns the value that was stored  
//in the shared currency variable called  
//myTotal in the subreport  
Shared CurrencyVar myTotal;  

Open in new window

4. Place @MainFormula in a main report section that is beneath
the section containing the subreport.

It is critical that @MainFormula be in a section that occurs after the section containing the subreport due to the order of formula evaluation in Crystal reports which works from top to bottom. For @MainFormula to work, @SubFormula must be evaluated first and the only way to ensure that is to put the subreport containing the formula into a section before @MainFormula.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TSFLLCAuthor Commented:
You're delving into an area I've never gone....

<<'In the subreport, create a formula similar to ...>>
OK.  I understand the logic.  But I'm fuzzy about what you mean by 'create a formula'.  
Do you mean create a Formula field?  And put this code in it?

<<Put this formula in a section below all the detail sections such as the report footer.>>
Report footer has multiple options for placing code.  

Can you elaborate a little more or am I missing something?
Yeah, a formula field. Right click Formula Fields in the Field Explorer and click new. Give it a name and paste the code into the formula.

Then you can drag and drop your new formula field onto the canvas into any section you like.
TSFLLCAuthor Commented:
I thought I posted again last night.  Apparently typed it but didn't hit submit.

I've now spent several hours last night and this morning trying to position things in the right place on the mainreport for this shared variable to populate.  Seems like the only place it will display is if I put it in the report footer.  

Although it prints in the report footer, I can't include a reference to it in any group footers where it will print a valid amount.  Prints 0.00.
I'm at a loss and under a time crunch this morning.
TSFLLCAuthor Commented:

Time was of the essence this morning.  And I'm thinking you live in a different time zone.

At any rate you put me on the right track.  I did create another open question and got an answer as needed.

Thanks for the start.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.