Total of a column

Hi,
I am using the LINQ to find total amount in a data table column.

dt.AsEnumerable.Sun(Function(row) Convert.ToDouble(row(“Amount”)))

The amount field is having positive and negative amounts. So I need to add up, meaning negative needs to be converted to positive and find total amount. How can I do this?

Thank you so much,

Hi @A_Learner

Do you want to convert the negative values to positive values then calculate the total.

@A_Learner

dt.AsEnumerable().Sum(Function(row) Math.Abs(Convert.ToDouble(row("Amount"))))

@A_Learner

Try this

dt.AsEnumerable.Sum(Function(row) Math.Abs(Cdbl(row("Amount").ToString)))

Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.