Linq query to sum the 5 column values and save in new column

Hi,

Another approach: can you try the following sample?

dt.AsEnumerable.Select(Function(r) dt.CLone.LoadDataRow( r.ItemArray.SkipLast(1).Concat({r.ItemArray.SkipLast(1).Sum(Function(o) CDbl(o.ToString))}).ToArray(),False)).CopyToDataTable()

Sample
Sample20240226-2 (2).zip (10.1 KB)

Or we can also achieve it using DataColumn.Expression as the following

dt.Columns(4).Expression = "[A]+[B]+[C]+[D]"

image

Regards,

1 Like