Solved

# Summing Across Multiple SubReports and Passing to Main

Posted on 2010-01-04
668 Views
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.
0
Question by:rbrigh1

LVL 100

Accepted Solution

Baisc idea

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

LVL 100

Expert Comment

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
Initial declaration formula
Details
DetailsA
Subreport1
DetailsB
DetailsC
Subreport2
DetailsD
etc

mlmcc
0

Author Comment

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

LVL 100

Expert Comment

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

Author Comment

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

LVL 100

Expert Comment

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

LVL 34

Assisted Solution

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

## Featured Post

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
Hi, I am very much excited today since I'm going to share something very exciting Tool used for Analytical Reporting and that's nothing but MICROSTRATEGY. Actually there are lot of other tools available in the market for Reporting Such as Co…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…