Hi experts. I am performing a sum operation, but the result summation was incorrect, after several debuggin, I discovered that I had there was 2 similar values but the sum ignored one of them.Please how do I fix this
- First use Read Range activity to read the data from excel file and will give output as DataTable. Let’s say ‘DTExcelData’.
-
And then try below expression to sum of specific column from DataTable.
Sum = DTExcelData.AsEnumerable().Sum(Function (row) Cint(row("ColumnName").Tostring)
Hi
May I know how you were actually trying to sum the column value
dtSum.AsEnumerable.Sum(Function(r) If(Information.IsNumeric(r(“Amount”).ToString.Trim), CDec(r(“Column13”).ToString.Trim), 0))
dtSum.AsEnumerable.Sum(Function(r) If(Information.IsNumeric(r(“Amount”).ToString.Trim), CDec(r(“Amount”).ToString.Trim), 0))
Hi
There is a small change in the expression
Instead of information put it as r
Like this
dtSum.AsEnumerable.Sum(Function(r) If(IsNumeric(r(“Amount”).ToString.Trim), CDec(r(“Amount”).ToString.Trim), 0))
Cheers @RPA-botDev
It’s showing compiler error, public shared Function IsNumeric As boolean has no parameters and it’s return type cannot be indexed
Fine
Can I see the changes you have made
dtSum.AsEnumerable.Sum(Function(x) If(x.ToString.IsNumeric(x(“Amount”).ToString.Trim), CDec(x(“Amount”).ToString.Trim), 0))
Try with this
dtSum.AsEnumerable.Sum(Function(r) If(IsNumeric(r(“Amount”).ToString.Trim), CDec(r(“Amount”).ToString.Trim), 0))
Cheers @RPA-botDev
An error cannot refer to an instance of a class without a shared member initializer occurred on IsNumeric
Assign: Conversion from string “” to type ‘Integer’ is not valid.