I was looking for a better way to handle this expression:
=IIf(Sum(Fields!DestElectronic.Value) > 0, 1 - Count(Fields!counter.Value) / Sum(IIf(Fields!DestElectronic.Value = 1, 1, 0)), 0) *-1
Lets say that:
Count(Fields!counter.Value) = 325
and that
=Sum(Fields!DestElectronic.Value) = 201
That should be 62%, my problem is that if I leave off that *-1 (Multiply by negative 1), it will return as -62%. Which makes sense.
If i flip the equation around, then it returns 38% (Which also makes sense.)
My concern with this is having that *-1 just hanging out there, and I worry that it could produce unforeseen results.
My goal is to return 62%. This value will be added up to 3 others that should always total 100.
So could this be written better?
You say that Sum(Fields!DestElectronic.Value)
equals 201, but what does Sum(IIf(Fields!DestElectronic.Value = 1, 1, 0))
equal?
Assuming that also equals 201 which is what I think you meant, then what you have is 1 - 325 / 201
which equals 1 - 1.61692
which is why you are getting a negative.
Without knowing what the rest of your dataset looks like, you can get this to return 62% with these specific given values by taking out the leading 1 -
and flipping the fraction around to
Sum(IIf(Fields!DestElectronic.Value = 1, 1, 0)) / Count(Fields!counter.Value)
But make sure to test that out with other values of your dataset. Alternatively, you could do
Count(Fields!counter.Value) / Sum(IIf(Fields!DestElectronic.Value = 1, 1, 0)) - 1
Note that these two expressions return slightly different answers: the former returns 0.61846
while the latter returns 0.616915
. So depending on what exactly you are trying to accomplish, one of these methods is likely not correct. The latter gives you the positive version of the answer you were previously getting, so I would assume that is what you are looking for. But it is impossible to say without know what you are trying to accomplish.