How to calculate total in entire datatable?

This data table how to calculate total for all row.

shrtname KTN KCN KHC KCH KHO KSM KTV Total
07-Mar 14 3 13
03-Jan 15 30 23 15 47 11 34
Total 39 30 26 15 60 11 34

Hi @domsmgtmeet22

Try this in Assign acitivty

dt.Columns("Total").Expression = "[KTN]+[KCN]+[KHC]+[KCH]+[KHO]+[KSM]+[KTV]"

Regards

please fully explain it

how to use assign activity

Hi @domsmgtmeet22

Formula to write in write cell activity

=SUM(B5:H5)

Hi @domsmgtmeet22

Can you try below

(From d In DT.AsEnumerable
 Let t = {"KTN","KCN","KHC", "KCH","KHO","KSM","KTV"}.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

Regards,

Hi @domsmgtmeet22

=> Read Range Workbook
image
Output-> dt
=> Use below syntax in Assign:

Save to: dt

Value to Save: (From d In dt.AsEnumerable
 Let t = {"KTN","KCN","KHC", "KCH","KHO","KSM","KTV"}.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

=> Write Range Workbook dt
image

Sequence10.xaml (8.3 KB)

Regards

solve in Datatable???

1 Like

Yes. @domsmgtmeet22

You can solve it in datatable.

Regards

Hi @domsmgtmeet22

Try this

(From d In DT.AsEnumerable
 Let t = {"KTN","KCN","KHC", "KCH","KHO","KSM","KTV"}.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

Input:

image

Output:

Cheers!!