Leandro Rodrigues


I need to do a function in my report, i'm trying use =Sum(Fields!FlagPresents.Value) but it sum all value in my table, i need some how =Sum(Fields!FlagPresenca.Value = 1), i want that when my value = 1 then sum, but i don't know how i can do it. Help me please. Thanks a lot!





Re: SUM in Report

larry smithmier


Hello Leandro,

I belive something like:

Code Block

=sum(iif(Fields!FlagPresenca.Value=1,1,0))

will do what you want. The expressions in SQL Server Reporting Services can use Visual Basic syntax so the IIF works as described here:

http://msdn2.microsoft.com/en-us/library/27ydhh0d(VS.71).aspx

Good luck!

Larry Smithmier






Re: SUM in Report

Leandro Rodrigues

Larry,

Thanks was it, but is sum all value, for sample if there are 2 value how 14 i'll have a result 28, and i wanted 2, get it, Can you help me your first anwers is correct after i mark how response valid.

Tkank you a lot!







Re: SUM in Report

Poochi74

I think what you need is count function.

Code Block

=Count(IIf(Fields!MyField.Value = 14, "1", Nothing))

This should give you the count of 2. Count function will count all the non-null values.




Re: SUM in Report

Leandro Rodrigues

Poolchi74,

I used =Count(IIf(Fields!MyField.Value = 14/14)) workek normal, may be that your code worked too. I didn't test. Thabk you.