简体   繁体   English

SSRS - 使用不同数据集字段的表达式

[英]SSRS - Expression using different dataset fields

I have a report with multiple data-sets. 我有一个包含多个数据集的报告。 Different fields from different data-sets are used in different locations of the report. 来自不同数据集的不同字段用于报告的不同位置。

In one part of the report, I need to do a calculation using fields from two different data-sets. 在报告的一部分中,我需要使用来自两个不同数据集的字段进行计算。 Is this possible within an expression? 这可能在表达式中吗?
Can I somehow reference the data-set the field is in, in the expression? 我可以在表达式中以某种方式引用该字段所在的数据集吗?

For example, I'd like to do something like this: 例如,我想做这样的事情:

=Fields.Dataset1.Field / Fields.Dataset2.Field

You can achieve that by specifying the scope of you fields like this: 您可以通过指定字段的范围来实现这一目标,如下所示:

=First(Fields!fieldName_A.Value, "Dataset1") / First(Fields!fieldName_B.Value, "Dataset2")

Assuming A is 10 and B is 2 and they are of type numeric then you will have the result of 5 when the report renders. 假设A是10而B是2并且它们是数字类型,那么当报表呈现时,您将得到5的结果。

When you are in the expression builder you can choose the Category: Datasets, your desired dataset highlighted under Item: and then double click the desired field under Value: and it will appear in your expression string with the scope added. 当您在表达式构建器中时,可以选择“类别:数据集”,在“项目:”下突出显示所需的数据集,然后双击“值”下的所需字段,它将显示在添加了范围的表达式字符串中。

Using same logic you can concatenate two fields like so: 使用相同的逻辑,您可以连接两个字段,如下所示:

=First(Fields!fieldName_A.Value, "Dataset1") & “ “ & First(Fields!fieldName_B.Value, "Dataset2")

As PerPlexSystem writes, asuming you only want to compare the first value from a dataset with values from another dataset, you can use the First function. 正如PerPlexSystem所写,假设您只想将数据集中的第一个值与另一个数据集中的值进行比较,则可以使用First函数。

However, if you want to compare the values of each row from one dataset with with the values from each row of another dataset, then you will need to use a subreport - see here for further details. 但是,如果要将一个数据集中每行的值与另一个数据集的每一行的值进行比较,则需要使用子报告 - 有关详细信息,请参阅此处

Another option is to use a parameter as a variable. 另一种选择是使用参数作为变量。 This is helpful if you want to create a calculated field in one of the datasets. 如果要在其中一个数据集中创建计算字段,这将非常有用。 This is best applied when the parameter value comes from a dataset with a single record. 当参数值来自具有单个记录的数据集时,最好应用此方法。

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

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