Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SUM in an RDLC report on decimal gives weird result

Tags:

c#

rdlc

I'm trying to generate an RDLC report where one column, Amount, is going to have a "Total" row at the bottom. This isn't weird stuff, it's a very basic RDLC report, but instead of getting the normal "Total" value at the bottom I get something else, allow me to demonstrate:

enter image description here

It shouldn't say 97,140.00, it should say 971,40 so I'm a bit confused. The column is summarized like this:

=Sum(CDec(Fields!Amount.Value))

I have to convert it first for some reason otherwise I get an #Error instead of the wrong number. This is weird as well as the model property is a decimal and the DataTable property I'm using is a decimal.

My only guess is that it has something to do with me being swedish and using comma as decimal separator instead of a period.

like image 441
Maffelu Avatar asked Sep 09 '12 10:09

Maffelu


3 Answers

The problem is obviously in CDec function. If you are sure that there is no other way for not using CDec try this: CDec(Sum(Fields!Oil_Gas.Value)) or this: FormatNumber(CDec(Sum(Fields!Oil_Gas.Value)),2) or this: FormatNumber(Sum(Fields!Oil_Gas.Value),2)

I couldn't really reproduce your problem but all mentioned solutions works for me.

like image 56
nzic Avatar answered Dec 20 '22 00:12

nzic


This solution worked for me. Try this

=ROUND(Sum(Fields!Outros.Value, "DataSet1"),2) 
like image 36
Matiullah Khan Avatar answered Dec 20 '22 00:12

Matiullah Khan


Solved problem as the error was in the datatable. As I was generating the datatable to throw in I didn't set the DataColumn type, so they all defaulted to string. For some reason CDec() and FormatNumber() didn't work even though they were handled as string by the datatable.

Anyhow, after properly creating the datatable with the correct data types for each column it worked.

like image 33
Maffelu Avatar answered Dec 20 '22 00:12

Maffelu