views:

1901

answers:

2

I have a report with a dataset that has a column with booleans. In the table footer I want to display x / y where x is how many rows that were true and y is how many rows there was total.

Currently I have this:

=Count(Fields!Transfered.Value).ToString() + " / " + CountRows().ToString()

But the first becomes same as the last part. I then tried this:

=Sum(Fields!Transfered.Value).ToString() + " / " + CountRows().ToString()

But that generates an error, which I guess I can understand. I thought that if I converted the booleans into numbers where true is 1 and false is 0, then it could work out nicely. But how can I do that? Or is it a smarter way to do this all together?

Update: Have now also tried

=Sum(CInt(Fields!Transfered.Value)).ToString() + " / " + CountRows().ToString()

And got a negative result... O.o

Also found a way that worked, which I posted as an answer. But I won't accept it as an answer yet incase someone has a better way to do this =)

+1  A: 

Figured out a way to do it, although there is probably a better more clear and logical way...

=Sum(IIF(Fields!Transfered.Value, 1, 0)).ToString() + " / " + CountRows().ToString()
Svish
+3  A: 

I can tell you why things went wrong...

  • Count(Fields!Transfered.Value) is simply the number of rows. aka CountRows()
  • Sum(Fields!Transfered.Value) is trying to aggregate "true" or "false" = error
  • Sum(CInt(Fields!Transfered.Value)) will sum -1 and 0 because VB.NET true = -1
  • Sum(IIF(Fields!Transfered.Value, 1, 0)) fixes the sign issue = your solution

To avoid the extra IIF, you could use negate the sum of all the -1s

= -Sum(CInt(Fields!Transfered.Value)).ToString() + " / " + CountRows().ToString()

In the end, either solution would be OK and both are equally kludgy

gbn
Thanks! Things are clearer now :D (Why would anyone decide to make true = -1??)
Svish
Dunno. To make people hate VB.Net? ;-)
gbn
Well, they have done a good job of that anyways :p C# FTW!
Svish