I have the following excel sheet. I wanted to get the sum for the Net Amount column and then put the sum at the end of the Net Amount column.
Note, this excel spreadsheet is an output coming from a data table.
So technically what I need is to get the sum of all the values in the Net Amount before writing it into an excel spreadsheet. The values in inside the “()” are negative value, plus in some rows there are values that have “-” in them.
terate through each row in the DataTable using a For Each Row activity.
Within the loop, use the Assign activity to assign the value of the current row and column to a variable. For example, if you want to calculate the sum of the “Amount” column, you can assign the value of the current row and column to a variable called “amount” using the following expression: amount = row("Amount").ToString().Replace(",", "")The Replace(",", "") method is used to remove the commas from the value, making it suitable for mathematical calculations.
Use the Add To Collection activity to add the numeric value of the “amount” variable to a List(Of Double) variable called “amountList”. This will help in storing all the numeric values for later sum calculation. Set the TypeArgument of the Add To Collection activity as Double.
After the loop, use the Assign activity to assign the sum of the values in the “amountList” to a variable called “totalAmount”. Use the following expression: totalAmount = amountList.Sum()The .Sum() method is used to calculate the sum of all the values in the “amountList”.
Hello @redanime94
One more alternate method is below:
Add “Add DataRow” activity
in ArrayRow pass this array= {"",dt_Input.AsEnumerable().Sum(Function(row) Double.Parse(row("Net amount").ToString, NumberStyles.Any) ).ToString,"","","",""} Please adjust the array according to your table