How to sumup String values in a datatable

datatable
excel
activities

#1

Hi Guys,

I am facing a trouble that:1

  1. String values can’t be summarized due to datatype issues;
  2. If I did convert the column of String values into int32, then I couldn’t sumup the numeric values unfortunately.

So can anyone help take a look at my flowchart, and tell me where I made mistakes?

Thanks a lot!
sample 1

datatble col sumup Phil.xaml (12.1 KB)


#2

Hello there,
You do have an option while building datatable ,it would’ve been easier if you change your data type to int while building.
Convert.ToInt32(dtAllRows.Compute(“Sum(Cost)”,String.Empty))

datattype

However if its already in string type you could try this out:
dtAllRows.AsEnumerable().Sum(x =>Convert.ToInt32(x[“Cost”]))

For the reference:
datatble col sumup Phil.xaml (16.9 KB)


#3

Great Thanks !! @ddpadil


#4

Hi @Phil_Wu,
A single activity will do the convert the type and do the sump. Check it below.

Regards
Balamurugan


How to sum all values in a column of an excel/Datatable?