Sum a column in subreport and show in main report

Stimulsoft Reports.NET discussion
prajan
Posts: 49
Joined: Tue Apr 23, 2013 1:28 pm

Sum a column in subreport and show in main report

Post by prajan »

Hi,
I have a report with two sub reports. I need to get the sum of columns from each of the sub report to be shown in the main report.
Can you please let me know how this can be handled?

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Sum a column in subreport and show in main report

Post by Alex K. »

Hello,

Please send us your report with test data for analysis.
Also please try to use the Totals.Sum() function.

Thank you.
prajan
Posts: 49
Joined: Tue Apr 23, 2013 1:28 pm

Re: Sum a column in subreport and show in main report

Post by prajan »

Hi,
PFA the report and the data for the report.
Currently I am getting the sub report column totals in the sub-report itself.
I would like to get these totals in a Footer in the main report so that both the totals come at the end of the report.

Thanks
Attachments
BSRep.mrt
(89.68 KiB) Downloaded 194 times
Data for Rep.xlsx
(11.16 KiB) Downloaded 191 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Sum a column in subreport and show in main report

Post by Alex K. »

Hello,

In this case, as a way, you can use the additional variables and DoublePass. In first pass you can calculate necessary sum by column, sets value for variable and use these variables on main page.

Thank you.
prajan
Posts: 49
Joined: Tue Apr 23, 2013 1:28 pm

Re: Sum a column in subreport and show in main report

Post by prajan »

Can you please give an example as to how to use Double pass?

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Sum a column in subreport and show in main report

Post by Alex K. »

Hello,

Please check the sample report in the attachment.

Thank you.
Attachments
ReportSample.mrt
(18.84 KiB) Downloaded 336 times
prajan
Posts: 49
Joined: Tue Apr 23, 2013 1:28 pm

Re: Sum a column in subreport and show in main report

Post by prajan »

Hi,
I checked the report, but didn't understand what the {SumSubReport} actually calculated. How is it taking any value from the sub-report?
If I use the same in my report, I get the following error :
"error CS0103: The name 'SumSubReport' does not exist in the current context"
Please let me know how to resolve the same.

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Sum a column in subreport and show in main report

Post by Alex K. »

Hello,

Please check the BeforePrint event of DataBand on SubReport. In this event calculating the value for SumSubReport variable.

Thank you.
prajan
Posts: 49
Joined: Tue Apr 23, 2013 1:28 pm

Re: Sum a column in subreport and show in main report

Post by prajan »

Hi,
Thanks for the help. It worked.
But I didn't give the if(IsFirstpass) condition. Is that ok? Or will it cause a performance issue?
Please let me know.
Thanks.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Sum a column in subreport and show in main report

Post by Alex K. »

Hello,

It is for correct calculation of value. In the first pass we get the value and in second show it.

Thank you.
Post Reply