Sum of column is not working if there is () for negative numbers

Sum of column is not working if there is () for negative numbers

Earlier I had

100
-100
200
-200

And this worked - dt.AsEnumerable().Sum(Function(row) row.Field(Of Double)(“Amount”))

But now they have changed negative values to have ()

$100
($100)
$200
($200)

The same formula isn’t working anymore. It fails with the following error -“Specified cast is not valid”

Hi @Krithi1

Try this LINQ query:

dt.AsEnumerable().Sum(Function(row) 
    Double.Parse(row.Field(Of String)("Amount").Replace("$", "").Replace("(", "-").Replace(")", "").Trim())
)

Regards

HI,

If you just changed cell format, can you try to turn off Visible Rows Only property and set RawValue at ReadFormatting in ReadRange activity, as the following?

Sample
Sample20240830-1.zip (9.7 KB)

Regards,