问题
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