Friday, February 17, 2012

counting occurrences of a value

I have a column in a report with values Y or N or V. In the header, I have to show the number of times each value appeared.

I used RepeatingValue() with IIF() but it's counting all the values as same, e.g., if there are four occurrences of Y, two of N and one of V, I want something like this:

Y Cnt=4, N Cnt=2, V Cnt=1

My assumption was that this will work (white spaces added for readability:

=iif(

Fields!myCol.Value = "Y",

"Y Cnt=" & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

iif(Fields!myCol.Value = "N",

"N Cnt= & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

iif(Fields!myCol.Value = "V",

"V Cnt= & RunningValue(Fields!myCol.Value, Count, "dsMyDataSet"),

"NULL"

)

)

)

Please help.

Can we declare variables and use them to keep the total?|||

As before, no one could help. After trying millions of different ways, I found the solution (white spaces for readability):

="Y Cnt=" &

Count(

Switch(Fields!myCol.Value = "Y", 1)

, "dsMyDataSet"

)

& ", N Cnt=" &

Count(

Switch(Fields!myCol.Value = "N", 1)

, "dsMyDataSet"

)

& ", V Cnt=" &

Count(

Switch(Fields!myCol.Value = "V", 1)

, "dsMyDataSet"

)

No comments:

Post a Comment