How to sum all rows into a total column without a set number of columns?

Hi All,

I’d like sum up all rows in a datatable without a for each because the number of rows can be very big. The number of columns is unknown, so i can’t simply add all the row(columns) + row(Columns)…

DT needs to be structured as follows.

Col1 Col2 Col3 Total
1 2.11 3.11 6.22

Any suggestions on how to do this?

Hope to hear from you.

Please mark solved if it answers your questions.

Datatable.AsEnumerable().Sum(Function(row) row.Field(Of Integer)(“Values”))

Additional information:
You have to make sure that the Column is set as type Integer or Decimal.


Hi Sarmad,

Thanks for your reply, but im looking to get the total of all colums in the Total Column like below, but then with out a for each activity, because the activity is taking to long because the number of rows can be very big.

Col1. Col2. Col3. Total
1 2 3 ???
2 3 6 ???

referring to below:

just adding 1 col for the sum and include the calculation within the LINQ:

Find starter help here:
ListDoubleArray_VariantLength_ToDataTable_RowSumAdd.xaml (8.3 KB)

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