Sum of the columns in a datatable


I have a datatable in which all the columns are in string format,out of which one column name is ‘Price’.

I want to extract the sum of that column and the values contains ‘$’ as well…

a quick shot would be following:

usa an assign activity:
To: YourSumVar of DataType Int32
Statement: YourDataTableVar.AsEnumerable.Sum(Function (row) CInt(row(YourColumnNameOrIndex).toString.Substring(1)))

The Idea behind of the statement was:

  • removing the $ sign with the substring method (starting at 2nd position)
  • converting remaining string to Integer
  • Using the Sum function to sum up all values

In case of the existens and position of the $ sign is not reliable a regex statement instead of the substring method would be more recommandable.

Happy Automation :slight_smile: let us know if it is working at your end


@ppr Datatype if taken INT32 ,decimal values not coming…

Give a try in Shifting From Cint Tour Cdbl or one Of The Convert.toxx Methods.
Dort forget also 2 change the datarype of sumresult

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.