Summing Across Multiple SubReports and Passing to Main

Because of the nature of database, I have multiple subreports being used for calculations for monthly performance. The report for Oct is the same as Nov and Dec (just the time period is different in the subreports).  In the main report I am trying to count the number of times a metric is met in each of the subreports.

I have tried using the "Shared NumberVar y" method. However, I can only get information for one subreport. Can't figure how to sum up the total between all the subreports.
rbrigh1Asked:
Who is Participating?
 
mlmccCommented:
Baisc idea

In the main report add a formula to the report header
WhilePrintingRecords;
Global NumberVar TotalMet;
Shared NumberVar subMet;
''

In the subreport
WhilePrintingRecords;
Shared NumberVar subMet;
SubMet := value
''

In the main report immediately after the subreport
WhilePrintingRecords;
Global NumberVar TotalMet;
Shared NumberVar subMet;
TotalMet := TotalMet + subMet;
''

Repeat the above for each subreport.
It might be easier to use separate shared variables for each suubreport.

mlmcc

0
 
mlmccCommented:
I would also put each subreport in its own section and have a section below it that the main report uses only to do the total

MainReport
  Report header
       Initial declaration formula
  Details
      DetailsA
           Subreport1
      DetailsB
           Formula to add subreport1 value
      DetailsC
           Subreport2
      DetailsD
           Formula to add subreport2 value
etc

mlmcc
0
 
rbrigh1Author Commented:
The main report is using the detail section for other record queries. So adding mutliple detail sections doesn't play well.  

submet can be seen in the subreports but the function "TotalMet := TotalMet + subMet;" does not appear to be summary the variables.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mlmccCommented:
Just use that method for the section with the subreports.

You can't use a shraed variable or a formula that uses shared variables in summary functions.
You have to do the sum manually.  Thus the formula that sums the shared values.

mlmcc
0
 
rbrigh1Author Commented:
understood.  I was only indicated that I don't really have the option to use the multiple detail sections.  Currently all subreports are in the same report header.  Your method seems to need multiple sections to work. If that is the case, not sure I will be able to use it.
0
 
mlmccCommented:
You can have multiple report header sections.

If you don't want to use that method then just use different variables for each subreport.  Then you can total them any time.  The method with multiple sections avoids the issues of losing the value between subreports.

mlmcc
0
 
James0628Commented:
In theory, using something like

Shared NumberVar SubMet;
SubMet := SubMet + value;
""

 in each subreport should work, whether the subreports are in the same section or different sections, and once all of the subreports have been executed, SubMet would have the total from all of the subreports.

 In practice, it might be "safer" to use a different variable (eg. SubMet1, SubMet2, etc.) in each subreport, and then add them together in the main report.

 Either way, the formula in the main report that tries to get the total from the variable(s) has to be in a section _after_ the one that the last subreport is in.  If all of the subreports are in the same report header section, any section after that should be fine.


 > submet can be seen in the subreports but the function
 > "TotalMet := TotalMet + subMet;" does not appear to be
 > summary the variables.

 FWIW, if you used the formulas that mlmcc posted and all of your subreports are in the same section, you will get the total from just one subreport, because the subreport formula used SubMet := value, so when each subreport was executed, it reset SubMet to the value from that subreport.  The idea was to update TotalMet in the main report in between each subreport, but if the subreports are all in the same section, that's not an option, and you'll just end up with the SubMet value from whichever subreport was executed last.

 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.

All Courses

From novice to tech pro — start learning today.