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”))
You have to make sure that the Column is set as type Integer or Decimal.
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:
working with this sample list:
lets init an empty datatable and retrieve the length of longest array within the list
Lets add datacolumns of datatype double to the datatatable - as many as we do have items in the longest array
for the column name we do use the index output from for each as well
lets create the row itemarrays and add the datarows to the datatable:
find starter help here:
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.