How to get the value for each row

Hi All
is their a way to get the total of a row as shown below
way to get the total as a Var
Thank you

Hi @Tharusha_Fernando

Please follow the below steps,

  1. Read the excel.
  2. Drop ‘For Each Row’ activity and provide datatable variable.
  3. Inside ‘For Each Row’ assign the int variable and give value like this, Convert.ToInt32(row(YourColumnName).ToString)+Convert.ToInt32(row(YourColumnName).ToString)+Convert.ToInt32(row(YourColumnName).ToString)+Convert.ToInt32(row(YourColumnName).ToString)

Attached workflow for your reference,

Feel free to reach us at any time if you have doubts. Thanks.

Happy Automation

1 Like

@Tharusha_Fernando
give a try on following

prepare a result datatable e.g. dtResult = dtOrigVar.Clone
Add a column Total to dtResult with add datacolumn activity

use an assign activity:
left side: dtResult
right side:

(From d in dtOrigVar.AsEnumerable
Let t = {"car loan","housing loan","food", "transport"}.Sum(Function (x) Convert.ToInt32("0" & d(x).toString.Trim))
Let ra = d.ItemArray.Append(t).toArray
Select dtResult.Rows.Add(ra)).CopyToDataTable
4 Likes

Thank for commenting
i have around 30 Column so i cannot write all the column name is their any way to mention the Range of the columns that i want to add

This is the look of my DataTable
B4:AE15

lets assume you want to sum up all columns:
Let t = d.ItemArray.Sum(Function (x) Convert.ToInt32(“0” & x.toString.Trim))

Lets assume you want to sum up not all columns but all with the name 1,2,3…30

Let t = Enumerable.Range(1,30).Sum(Function (x) Convert.ToInt32("0" & d(x.toString).toString.Trim))
1 Like

Hi @ppr
What does d Stands for

it is like a parameter and represents the current item on which is worked

1 Like

it worked thank you

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.