GuidoG
GuidoG

Reputation: 12014

Visual Studio ReportViewer Sum not working on decimal fields

I have a simple report in Reportviewer with 2 checkboxes on the footer that should display a sum. The sum should however be conditional :
Only if the field "Checked" is true than the value must be included in the sum.

For the first field this works without problem, but for the second field I get #error on the report.

The first field is an integer field, the second is a decimal field. Here is the expression I use in the value property of both textboxes :

=Sum(IIf(Fields!Checked.Value, Fields!TotaalBedrag.Value, 0), "DataSet1")
=Sum(IIf(Fields!Checked.Value, Fields!TotaalAantalKM.Value, 0), "DataSet1")

Field Checked is boolean and not null
field TotaalBedrag is integer and not null
field TotaalAantalKM is decimal and not null

the sum is correct for field TotaalBedrag but the sum for field TotaalAantalKM returns #error

If I write

=Sum(Fields!TotaalAantalKM.Value, "DataSet1") 

than I do get a correct sum so I guess there is nothing wrong with this field. The only difference between the 2 fields is that one is int and the other is decimal. Is there someting special I need to do for decimal fields maybe ?

Upvotes: 0

Views: 1948

Answers (2)

jacktric
jacktric

Reputation: 393

For decimal values you must use "0D" instead of "0". So your expression will become:

=Sum(IIf(Fields!Checked.Value, Fields!TotaalAantalKM.Value, 0D), "DataSet1")

Upvotes: 0

vignesh
vignesh

Reputation: 97

The data type of the column 'TotaalAantalKM' is Decimal so you need to either convert the default value to 0.00 or cast the column to double

=SUM(iif(Fields!Checked.Value,cdbl(Fields!TotaalAantalKM.Value),0.00))

Upvotes: 2

Related Questions