• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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.
0
TSFLLC
Asked:
TSFLLC
  • 3
  • 2
1 Solution
 
meumaxCommented:
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:
//@SubFormula  
//Stores the grand total of  the  
//{Orders.Order Amount} field  
//in a currency variable called 'myTotal'  
WhilePrintingRecords;  
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:
//@MainFormula  
//Returns the value that was stored  
//in the shared currency variable called  
//myTotal in the subreport  
WhilePrintingRecords;  
Shared CurrencyVar myTotal;  
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.

0
 
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?
0
 
meumaxCommented:
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.
0
 
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.
0
 
TSFLLCAuthor Commented:
meumax,

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.

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_27478315.html

Thanks for the start.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now