We help IT Professionals succeed at work.

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

TSFLLC asked
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.
Watch Question

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.


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.


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.



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.