# Summing based on value of boolean

• ### Question

• Hi, I want to have a sum row for a boolean column that gives the total for that column where the boolean = true. Is it possible to do this?
Wednesday, April 29, 2009 9:35 AM

• Hi Mike,

Let me ask you this. Does a column has a value of "Yes No No Yes Yes" or Col1 = Yes, Col2 = No, Col3 = No, Col4 = Yes and Col5 = Yes? Because it could be different on how to count them. If it's the first one, I suggest creating a custom code. An example would be:

Public Function CountYes(Str1 as String) AS integer
Dim b() as string
b=Split(Str1," ")

Dim i As Integer
Dim YesCtr as Integer
YesCtr = 0
For i = 0 To b.Length - 1
if b(i) = "Yes" then
YesCtr = YesCtr + 1
end if
Next
return YesCtr
End Function

and calling it using expression, i.e. =code.CountYes(Fields!Col1.Value).

If it is a second example, then a simple if stmt, depending on how many columns or fields you want to, can do it. I.e.
=iif(Fields!Col1.Value="Yes",1,0) + iif(Fields!Col2.Value="Yes",1,0) + ..... and so on. This will give count for each row.

Good luck.

Chicagoan ...
Wednesday, April 29, 2009 2:36 PM

### All replies

• Hello,

Do you mean sum of a column based on the other column of boolean type. If yes, then you can a sample is shown below

= IIF(Fields!boolean.Value = True, SUM(Fields!FieldName.Value) , 0)

Pavan http://www.ggktech.com
Wednesday, April 29, 2009 10:05 AM
• Hi, What I want is to check if each value in a column is true, then if so add 1 to the count. E.g. Column 1 -------- Yes No No Yes Yes So in this case I want to show that there were 3 yes's in the column. I have tried this, but it just counts all records, and not just the records where the field = true : = IIF(Fields!Still_Trading.Value = true, COUNT(Fields!Still_Trading.Value) , 0)
• Edited by Wednesday, April 29, 2009 11:23 AM
Wednesday, April 29, 2009 11:23 AM
• Try this,

Wednesday, April 29, 2009 12:24 PM
• Hi, This gives a count for ALL the rows, not a count for the rows where the boolean value = true.
Wednesday, April 29, 2009 1:03 PM
• Hi Mike,

Let me ask you this. Does a column has a value of "Yes No No Yes Yes" or Col1 = Yes, Col2 = No, Col3 = No, Col4 = Yes and Col5 = Yes? Because it could be different on how to count them. If it's the first one, I suggest creating a custom code. An example would be:

Public Function CountYes(Str1 as String) AS integer
Dim b() as string
b=Split(Str1," ")

Dim i As Integer
Dim YesCtr as Integer
YesCtr = 0
For i = 0 To b.Length - 1
if b(i) = "Yes" then
YesCtr = YesCtr + 1
end if
Next
return YesCtr
End Function

and calling it using expression, i.e. =code.CountYes(Fields!Col1.Value).

If it is a second example, then a simple if stmt, depending on how many columns or fields you want to, can do it. I.e.
=iif(Fields!Col1.Value="Yes",1,0) + iif(Fields!Col2.Value="Yes",1,0) + ..... and so on. This will give count for each row.

Good luck.

Chicagoan ...
Wednesday, April 29, 2009 2:36 PM