Sum of each column of multiple columns?

i have a multiple columns in datatable…i want sum of each column?

Hello @suneel070

In order to iterate through the data table, use a For Each Row activity.
Inside the loop, use an assign activity to get the sum of each column…
The code that can be used is something similar to this

TotalSum = Int32.Parse(row(“Column1”).ToString) + Int32.Parse(row(“Column2”).ToString)

This will give you the sum of all the columns of a particular row.

but column always change?how we get all each coloumn sum if collumns are dynamic??

Do something like this… We first need to know how many number of columns we have in the datatable because it is dynamic.

That you can do by getting the column count.

Int ColumnCount = DT.Columns.Count()

Now, inside the for each row activity we introduced earlier, let’s use another while loop, to loop through the number of columns we have incrementally…

So introduce another counter variable which will start from 0 and increment by one inside the while loop…

Now, inside the while loop, using the counter variable, we can get the total of each column like this…

Total = Total + Int32.Parse(row(CounterVarible).ToString)

And once the while loop is ended for each row, you will have the total value of the columns for that particular row…

Make sense?

Hi @suneel070

Loop the columns and
Use the below code to get sum of column

dt.Compute("Sum(<columnName>)", string.Empty);