How can I create an expression in an SSRS report similar to an Excel formula?

时间秒杀一切 提交于 2019-12-24 05:46:18

问题


I need to combine the results of multiple similar Stored Procedures into a single Tablix.

I'm using multiple Stored Procedures that return the same data, but for varying Units. So in one "cell" (I don't know if that is the correct terminology for a data field in a Tablix) I have an Expression like so:

=IIF((Fields!Week.Value="WK1"),Fields!Price.Value,"")

...which conditionally displays data when the value of the "Week" field is "WK1" and the Stored Procedure for a Unit value of "BARNEY" is the dataset.

After that (on the same row, in a column to the right in the Tablix) I need to show the same data from a different Stored Procedure where the Unit value being used is "RUBBLE". I need the Expression to reference an existing value (ItemCode) in the Tablix from the first Stored Procedure, so that both cells on the row are displaying values for the same ItemCode (but different Units).

That cell/field is a simple pointer to the ItemCode value returned from the Stored Procedure:

=Fields!ItemCode.Value

How can I use a formula to display the data for the ItemCode that the initial Stored Procedure is displaying data for on that row. Something like this:

=IIF((Fields!Week.Value="WK1" AND Fields.ItemCode=[Existing Item Code value in this row]),Fields!Price.Value,"")

?

IOW, what do I need in place of the "Existing Item Code value in this row" to make this work? Could it be something like this:

=IIF((Fields!Week.Value="WK1" AND Fields.ItemCode=TextboxItemCodeData.Value),Fields!Price.Value,"")

?


回答1:


If the main dataset for the tablix you are working in is BARNEY, then this is the basic lookup expression that you should start with to get data from the RUBBLE dataset.

=Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE")

In this situation, the Price will be returned when the ItemCode values match between the BARNEY and RUBBLE datasets.

This is the expression that may help you hide or show a value from the secondary dataset.

=IIf(Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Week.Value, "RUBBLE")="WK1", Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE"), "")

The first part of the IIf is checking the Week field in the RUBBLE dataset. If the value is WK1, then it displays the Price from the RUBBLE dataset; otherwise nothing.

This might work if you don't have to check the Week value in the RUBBLE data, and just checking in the BARNEY dataset will work.

=IIf((Fields!Week.Value="WK1"),Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE"),"")


来源:https://stackoverflow.com/questions/37690970/how-can-i-create-an-expression-in-an-ssrs-report-similar-to-an-excel-formula

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