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

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

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
rowfei
Asked:
rowfei
  • 8
  • 6
  • 4
2 Solutions
 
mlmccCommented:
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
 
rowfeiAuthor Commented:
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
 
mlmccCommented:
Yes.

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

mlmcc
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
rowfeiAuthor Commented:
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
 
James0628Commented:
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
 
rowfeiAuthor Commented:
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
 
mlmccCommented:
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
 
rowfeiAuthor Commented:
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
 
James0628Commented:
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
 
rowfeiAuthor Commented:
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
 
mlmccCommented:
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
 
rowfeiAuthor Commented:
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
 
James0628Commented:
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
 
rowfeiAuthor Commented:
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
 
mlmccCommented:
To display as a percent you need to multiply by 100 first.

mlmcc
0
 
rowfeiAuthor Commented:
Thanks, mimcc.

Do you need to multiply by 100 on formulas on both sub and main report?
0
 
mlmccCommented:
When you do the division you need to multiply by 100 to turn it into a percent.

mlmcc
0
 
James0628Commented:
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
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: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 8
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now