I’m trying to calculate the sum of a particular column ‘Amount’ in a Data Table. The data type of Amount is string. The Sum should be 0, but when I tried using UiPath, it provided me with an incorrect value.
Please find the screenshot below as an example:
Use this LINQ in Assign activity.
dt.AsEnumerable() _
.Where(Function(row) Not String.IsNullOrEmpty(row.Field(Of String)("Amount"))) _
.Sum(Function(row) Convert.ToDecimal(row.Field(Of String)("Amount")))
Can you try converting it to integer format .
Please send a screenshot of your activity from Studio
tried , not working.
if possible, please create the xaml and share
thanks in advance
Let’s convert it to Double
CDbl(dt.AsEnumerable() _
.Where(Function(row) Not String.IsNullOrEmpty(row.Field(Of String)("Amount"))) _
.Sum(Function(row) Convert.ToDecimal(row.Field(Of String)("Amount"))))
Output:
1 Like
This will definitely work ! Try this @madhabhazra0
Mark it as a solution if it is working
yes, it is workinh
thank you @Lalasa_Mulakaluri
1 Like
this is also working but within for each row this syntax is not working
LINQ avoids unwanted iterations so this wasn’t for For Each.