How to calculate sum of total in datatable?

need to calculate sum of total all columns…entire datatable.

for example datatable,

Date column1 column2 column3 column4 column5 column6 column7 Total
1-3 17 10 15 4 47 15 56
3-7 9 4 3 14 4 1
Total 26 14 18 4 61 19 57

Hi @saninfo273

Please check this

(From d In DT.AsEnumerable
 Let t = {"Column1","Column2","Column3", "Column4","Column5","Column6","Column7"}.Sum(Function (x) Convert.ToInt32("0" & d(x).toString.Trim))
 Let ra = d.ItemArray.Take(d.ItemArray.Length - 1).Concat({t}).ToArray
 Select DT.Clone.Rows.Add(ra)).CopyToDataTable

Output:

Regards,

Hi @saninfo273

(From d In DT.AsEnumerable
 Let t = {"column1","column2","column3", "column4","column5","column6","column7"}.Sum(Function (x) Convert.ToInt32("0" & d(x).toString.Trim))
 Let ra = d.ItemArray.Take(d.ItemArray.Length - 1).Concat({t}).ToArray
 Select DT.Clone.Rows.Add(ra)).CopyToDataTable

Hope it helps!!

@saninfo273 ,

Try this one.

Thanks,
Ashok :slight_smile:

upload assign activity image…

@saninfo273

If you find solution,Please do mark it as solution to close the loop and it will help others too.if you have any queries, can ask .

Regards

Here you go.

image

image

It’s easiest and simplest way.

Thanks,
Ashok :slight_smile:

out put is incorrect

the output is incorrect…

Date KTN KCN KHC KCH KHO KSM KTV Total
03-Jan 17 10 15 4 47 15 56 4.10155E+12
07-Mar 9 4 3 14 4 1
Total 26 14 18 4 61 19 57 4.14186E+12

@saninfo273

Please try this

It might be due to DataTable column data types. If it’s non numeric it will not work.