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.
2 Likes
Sarmad_Nadeem:
e
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 ???
ppr
(Peter)
May 28, 2021, 8:43am
4
referring to below:
@dyuonn.bakker
working with this sample list:
[grafik]
lets init an empty datatable and retrieve the length of longest array within the list
[grafik]
Lets add datacolumns of datatype double to the datatatable - as many as we do have items in the longest array
[grafik]
[grafik]
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:
[grafik]
Result:
[grafik]
find starter help here:
ListDoubleArray_Var…
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)
system
(system)
Closed
May 31, 2021, 8:44am
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.