Expression in SSRS not working as expected

≡放荡痞女 提交于 2019-12-10 15:12:21

问题


I have an SSRS report which I want to sum values of a field, but only if the value of another field is equal to 1, as I have made the report output a row number for each row. Bascially, I'm trying to sum the distinct values to come up with a total. Screenshot below. I'm getting an error for orders with more than 1 item. My expression used to calculate the Ship Cost (red text) is as follows

=SUM(IIF(Fields!RowNumber.Value = 1, Fields!WEIGHT.Value, 0))

But I'm getting the #Error. The cell that has the text #Error should be reading $11.25.


回答1:


I think you're likely getting a datatype mismatch in the aggregate; SSRS can't handle implicit conversions in these sort of IIf/aggregate expressions.

In your expression, 0 will be treated as an int, and assuming the underlying data type of Fields!WEIGHT.Value is decimal or double, this will throw a runtime error - if you preview in BIDS it should actually display the error.

To get around this you need to make sure the two IIf results have the same datatype - something like:

=SUM(IIF(Fields!RowNumber.Value = 1, Fields!WEIGHT.Value, 0.0))

or

=SUM(IIF(Fields!RowNumber.Value = 1, Fields!WEIGHT.Value, CDec(0)))

or

=SUM(IIF(Fields!RowNumber.Value = 1, Fields!WEIGHT.Value, CDbl(0)))

Depending on the underlying datatype you may have to try a few combinations but hopefully one of the examples will work correctly,




回答2:


See here: http://www.bidn.com/forums/microsoft-business-intelligence/reporting-services/589/how-to-sum-at-group-level

If your group is called "Order#", your expression should be:
=SUM(IIF(Fields!RowNumber.Value = 1, Fields!Weight.Value, 0),"Order#")



来源:https://stackoverflow.com/questions/18236373/expression-in-ssrs-not-working-as-expected

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