Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass summary values from subreport to main report? 1

Status
Not open for further replies.

jpicks

MIS
Joined
Oct 11, 2002
Messages
158
Location
US
Using Crystal 8.5

I am building a report that consists of a main report and one subreport.

I want to pass all the summary values for a group in the subreport to the main report as shared variables, but I have been unable to figure it out as of yet.

The subreport is of Gross Losses grouped by state.

ie.

State Sum(Gross Loss)
MN -100
WI -100
IL -100

The main report is of Gross Sales.

I want to pass each summary value from the subreport to the main report to calculate Net Sales

Any help or suggestions would be greatly appreciated!

-Jim



 
Jim,

I assume you are linking the subreport to the main report by state? In order to pass the info over, try this formula in the subreport to create a shared variable.

whileprintingrecords;
shared numbervar x:=Sum ({Grosslossfield});

Put this into your subreport, and use it as the total. I change the font color to white, so it won't show up in the main report.

Now, you also need to make sure the subreport passing the variable is in a section PRIOR to the main report, as it needs to process first.

In the main report, create another variable,

whileprintingrecords;
shared numbervar x


this will pull the passed info from the subreport into the main report.

Hope this helps?

Bob

 
Bob,

Thanks for your reply. Your suggestion seems like it will work fine.

I am not currently linking the subreport to the main report. What is the advantage of doing this and is it necessary in order to use the solution you provided?

Also, the subreport often has less states than the main report. Will this be a problem?

I'll give your solution a shot tomorrow morning.

Again, thanks for your help.

-Jim
 
Jim,
Linking the subreport to the main report will allow the data to 'match up' In other words, all the subreport data for WA will link to the main report data for WA. Otherwise, the shared variable will not know which group of states to reference.

Make sense?

Bob
 
Bob,

I see what you mean. I linked the reports on state.

I modified your formula so that it would sum gross loss on each state in the subreport.

WhilePrintingRecords;
shared numbervar x:=Sum ({GrossLoss}, {STATE});

The problem I am having now is that the only value that gets passed into main report is the last summary value to be calculated in the subreport.

ie.

Subreport contains the following values:

State Sum(Gross Loss)
MN -100
WI -200
IL -300

When I pass the shared variable to the main report and place the formula field in the group footer for state I get the following values:

State Shared Variable output
MN -300
WI -300
IL -300

Any thoughts on how to get around this?

Thanks,

Jim






 
Jim,
The subreport needs to be above the main report, so you need to make sure the variable is passed first. Group header, or insert a new group section above the main group and put it here.

You can also add a reset variable formula in the footer, like so,
WhilePrintingRecords;
shared numbervar x:=0;
that should reset the varible to zero, until the next section processes. Remember Crystal loops throuhg each group as it processes, and will process each linked subreport first.

Also, are you grouping the subreport by state as well? Then the built in summary function could be used.

I hope this is helping?

Bob
 
Bob,

Thanks again for all of your help! I would have been stuck without you.

Both reports are grouped by state. The subreport is linked on state.

My problem was that I was putting the subreport in the report footer and then trying to pass values from each group of the subreport to the corresponding group in the main report.

I placed the subreport in the state group footer (Section A) in the main report and everything worked great. Then I was able to include gross sales, gross loss, and calculate net sales in the state group footer (Section B) below the subreport.

Thanks again,

Jim
 
Good deal Jim!
Glad I could help.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top