Solved

Crystal Reports - Sub report shared variable text & % in Main report

Posted on 2015-01-27
18
157 Views
Last Modified: 2015-02-03
Hi,

I have several sub-reports that group by the one category. In the report footer of each sub report, I have a text field shows "Total number of Y" "/" "Total Number". Then the % fields. Like it below.

Category                                   Raw Score            %
A                                                     12/15               82%
B                                                     15/18               90%
C                                                      25/30              88%

                      Total:                       52/53                89%

How can I pass those two fields "52/53" & "89%" to my main report?

Thanks in advance.
0
Comment
Question by:rowfei
  • 8
  • 6
  • 4
18 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 40574502
Try this

In the main report report header add a formula
WhilePrintingRecords;
Shared NumberVar  TotalNumberofY;
Shared NumberVar TotalNumber;
Shared NumberVat TotalPercent;
""

Open in new window


In the subreport add a formula or modify the total display formulas

WhilePrintingRecords;
Shared NumberVar  TotalNumberofY;
Shared NumberVar TotalNumber;
TotalNumberofY := value you calculated for Y;
TotalNumber := value you calculated for total number;
display 52 / 53

Open in new window


Similarly for the %

In the main report in a section after the subreport
WhilePriintingRecords;
Shared NumberVar  TotalNumberofY;
Use the value for other calculations

Open in new window


mlmcc
0
 

Author Comment

by:rowfei
ID: 40574969
Thanks, Mimcc.

Just want to clarify for the codes below.

Should I put the text fields name instead of "display 52 / 53"?

WhilePrintingRecords;
Shared NumberVar  TotalNumberofY;
Shared NumberVar TotalNumber;
TotalNumberofY := value you calculated for Y;
TotalNumber := value you calculated for total number;
display 52 / 53
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40575091
Yes.

CStr(v,0) & " / " & CStr(TotalNumber )

mlmcc
0
 

Author Comment

by:rowfei
ID: 40575798
Thanks. As I add the following codes, I am getting error message: the remaining text does not appear to be part of the formula. Do you know why?

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
total_Y := sum({@total_Y});
total := sum{@total});
CStr(total_Y) & " / " & CStr(total)
0
 
LVL 34

Expert Comment

by:James0628
ID: 40576003
You're missing a "(" in this line.

total := sum({@total});


 Are @total_Y and @total actually formulas in your report?  Those are the same names you're using for the variables, so I just wanted to check.


 And if you want the displayed numbers to not have any decimals (eg. "52 / 53"), you'll need to include a format in the CStr functions.  For example:

CStr(total_Y, "#") & " / " & CStr(total, "#")

 James
0
 

Author Comment

by:rowfei
ID: 40576114
Yes, those formulas name are the same as the variables name.

I do see the "total_Y" "/" "Total" on the subreport, but blank on the main report. Below are the codes that I put.

In the main report footer, insert a formula with codes below:

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
""

In the sub report footer, insert a formula with codes below:

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
total_Y := sum({@total_Y});
total := sum ({@total});
CStr(total_Y, "#") & " / " & CStr(total, "#")
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 250 total points
ID: 40576162
Your formula in the main report should be

WhilePrintingRecords;
 Shared NumberVar total_Y;
 Shared NumberVar total;
 CStr(total_Y, "#") & " / " & CStr(total, "#") 

Open in new window


mlmcc
0
 

Author Comment

by:rowfei
ID: 40576474
Thank you, mlmcc.

Now I can see it on the main report. But it shows the last group's total_Y and total instead of summing of all groups? Do you know why?

Below is what is showing now:

Category                                   Raw Score            %
A                                                     12/15               82%
B                                                     15/18               90%
C                                                      25/30              88%

                      Total:                       25/30               88%
0
 
LVL 34

Expert Comment

by:James0628
ID: 40576639
I'm guessing that the subreport is in a group header or footer, and that you want to see the totals for an individual group in the subreport, but then grand totals at the end of the main report.

 If so, change the subreport formula to:

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
total_Y := total_Y + sum({@total_Y});
total := total + sum ({@total});
CStr(sum({@total_Y}), "#") & " / " & CStr(sum ({@total}), "#")


 I changed the formula to add the Sum's to the variables, and then display the Sum's at the end, instead of the variables.


 Also, just to check something, you said in post #40576114 that the first formula was in the main report _footer_.  It should be in the header.

 James
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:rowfei
ID: 40576690
Thanks, James.

The reason I didn't put first formula in the main report header because I have other fields need to be displayed. Do I really have to insert this formula to the main report header? Is that cause the issue?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40576703
You need to declare the shared variables in the main report before they get used in the subreport.  The formula doesn't display anything.

mlmcc
0
 

Author Comment

by:rowfei
ID: 40576782
Thanks you for the explanation, mlmcc.

For the % formula to insert in subreport, should I put the codes below:

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
total_Y := total_Y + sum({@total_Y});
total := total + sum ({@total});
sum({@total_Y}), "#") / (sum ({@total})

The formula below to insert to main report,

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
total_Y := total_Y + sum({@total_Y});
total := total + sum ({@total});
sum({@total_Y}), "#") / (sum ({@total})

Thanks,
0
 
LVL 34

Expert Comment

by:James0628
ID: 40577118
First of all, you altered the last line in the formula.  Are you trying to calculate the % there (eg. 89), or show the two totals (eg. "52 / 53")?  What you have in your post won't work, because you removed parts of the CStr functions, but not everything (eg. the "#" format for the first CStr).

 If you want to calculate the %, and just produce that numeric result (in the subreport):

sum({@total_Y}) / sum ({@total})


 At the end of the main report, the variables should have the totals from the subreport, so you just want to use the variables in the main report (and the @total_Y and @total formulas presumably don't exist in the main report, so you couldn't use them there anyway).  The variables already have the totals at this point, so you don't need to add anything to them or Sum them.

WhilePrintingRecords;
Shared NumberVar total_Y;
Shared NumberVar total;
// Assuming that you want to calculate the %
total_Y / total


 Also, as mlmcc explained, the first formula (in the main report header) doesn't produce any visible output on the report.  It ends with "", so it just produces an empty string.  But, FWIW, you could also just suppress that field on the report, or put the formula in a separate report header section and suppress that whole section.

 James
0
 

Author Comment

by:rowfei
ID: 40577241
Thank you so much, James.

Yes, I do want to calculate the %. I am able to display the right % in the main report. Just one last issue, the % current shows 0.89. I tried to format it to 89%. As soon as I made any changed under "Format Editor" to this fields, the % changes to "0". Do you know why? Just so wired.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40577388
To display as a percent you need to multiply by 100 first.

mlmcc
0
 

Author Comment

by:rowfei
ID: 40577504
Thanks, mimcc.

Do you need to multiply by 100 on formulas on both sub and main report?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40577629
When you do the division you need to multiply by 100 to turn it into a percent.

mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 250 total points
ID: 40578485
Change the calculation in each formula.  For example, change the last line in the formula in the main report to:

total_Y / total * 100

 Make a similar change to the calculation in the subreport formula.

 James
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now