Reporting Services - Count Column Values if equals A

北城余情 提交于 2019-12-18 15:04:04

问题


I have a dataset called 'dsAllStuTargetData' - i'm trying to count the number of the 'A' values that appear in the column 'Target'.

I'm doing this using a textbox with an expression, I can count the total number of values using the following:

=Count(Fields!Target.Value, "dsAllStuTargetData")

However when I try to count where the value equals 'A' it doesn't work.

=Count(IIF(Fields!Target.Value, "dsAllStuTargetData")="A",1,0)

回答1:


For this case you need a Sum, not a Count, i.e. something like:

=Sum(IIf(Fields!Target.Value = "A", 1, 0), "dsAllStuTargetData")

Count will just count the number of rows; the IIf doesn't do anything there - something like CountDistinct can be affected in certain cases but this will not work here.

However, Sum will take the total of all rows which meet the IIf condition, i.e. the total of all 1 values in the DataSet, which is what you're after.




回答2:


IIF wants it's arguments in the format:

IIF(condition, true part, false part)

Which would equate to something like

Count(IIF(Fields!Target.Value = "A",1,0),"dsAllStuTargetData")

Does that work?



来源:https://stackoverflow.com/questions/18892911/reporting-services-count-column-values-if-equals-a

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