简体   繁体   English

SSRS来自多个数据集和子报告的求和值

[英]SSRS summing values from multiple data sets and sub reports

I have a two data sets and a sub report in my SSRS master report. 我的SSRS主报告中有两个数据集和一个子报告。

I need to create a third - Grand total table or matrix that returns a field from each of the data sets and sub report. 我需要创建第三个-总计表或矩阵,该表或矩阵从每个数据集和子报表中返回一个字段。

It would look like this (to start) 看起来像这样(开始)

在此处输入图片说明

To start I built a table and added a columns to test this with the following values. 首先,我建立了一个表并添加了列以使用以下值对此进行测试。 (This is in the Grand Total Row) each element alone is in the respective row. (在“总计总计”行中),每个元素单独位于相应的行中。

=ReportItems!tps_actual4.Value + ReportItems!Textbox1230.Value

tps_actual4 comes from one dataset. tps_actual4来自一个数据集。 Textbox1230 comes from a different dataset. Textbox1230来自不同的数据集。

the first error that comes up reads: 出现的第一个错误是:

"The value for the DataSetName property is missing"

if i change my code to something that reads like this 如果我将代码更改为这样的内容

=First(ReportItems!tps_actual4.Value, "Master_Data_Set") + First(ReportItems!Textbox1230.Value, "Secondary_Data")

I get another error that reads: 我收到另一个错误,内容为:

The value expression for the textrun ''.. uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers. 

There is no one data set we are referencing here. 这里没有参考的数据集。 i'm not sure how to resolve this. 我不确定如何解决这个问题。

The second question is in the case of Textbox1230 it is returned 6 times as there are six lines of data. 第二个问题是在Textbox1230 ,由于有六行数据,它被返回6次。 How do i specifiy in my logic a case statement when to add Textbox1230 我如何在逻辑中指定要添加Textbox1230的案例声明

lastly I'm not even sure how to reference the sub report as we need to access two of the fields from the sub report as well. 最后,我什至不确定如何引用子报表,因为我们也需要访问子报表中的两个字段。

thank you. 谢谢。

Grand Total         column1 column2  
Dataset1 Values        a      x  
Dataset2 Values        b      y       … and so on
Subreport Values       c      x  
Grand Total Sums    a+b+c   x+y+z    

the above is an excel sampling hopefully it will help with the understanding -- the columns will continue the first row of data comes from one data set. 上面是一个excel样本,希望能帮助您理解-列将继续来自一个数据集的第一行数据。 The second from another etc and the Grand total adds the values together for a grand total. 来自另一个等的第二个和“总计”将值相加在一起得出“总计”。

The only thing you can do is to catch all the totals from different tablixes and summarize these values in a separate tablix. 您唯一可以做的就是捕获来自不同Tablix的所有总计并将这些值汇总到单独的Tablix中。 But you cant fetch values from a subreport, this works just with datasets, which are in the actual report. 但是您无法从子报表中获取值,这仅适用于实际报表中的数据集。 If you want to sum the subreport values as well I recommend to use @junketsu´s solution. 如果您还想对子报表值求和,我建议使用@junketsu的解决方案。

Lets say you have 2 Datasets in your report, each of them is the source of another tablix. 假设您的报表中有2个数据集,每个数据集都是另一个Tablix的来源。 In each tablix you need to add a total now 在每个Tablix中,您现在需要添加总计

'Tablix 1 total
=Sum(Fields!TestValue.Value, "Dataset1")  'This expression is in Textbox1

'Tablix 2 total
=Sum(Fields!TestValue2.Value, "Dataset2")  'This expression is in Textbox2

Now add a third tablix. 现在添加第三个tablix。 Write in the first textbox the folloing expression: 在第一个文本框中编写以下表达式:

=ReportItems!Textbox1.Value  

In the second textbox: 在第二个文本框中:

=ReportItems!Textbox2.Value 

And in the third textbox: 在第三个文本框中:

=ReportItems!Textbox1.Value + ReportItems!Textbox2.Value

The result for the thrid tablix will look like this: 第三tablix的结果将如下所示:

Dataset1 Total Value     11111
Dataset2 Total Value     22222
Overall Total            33333

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM