SSRS - Expression using different dataset fields

送分小仙女□ 提交于 2019-11-28 03:20:34

问题


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

回答1:


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.

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")



回答2:


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.

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.




回答3:


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.



来源:https://stackoverflow.com/questions/9676149/ssrs-expression-using-different-dataset-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!