Hi there @yogeshgyw,
Please try the following: dtTesting.AsEnumerable.Sum(Function (x) If(Double.TryParse(x.item("Column2").ToString, Nothing), Double.Parse(x.Item("Column2").ToString), 0))
This will convert the DT to an enumerable, then SUM the column value (as a double) if it is valid, otherwise it will simply add 0.
You will need to change the references for the DataTable (dtTesting) and columns (“Column2”).
Apologies for the delay, please let me know if it works!
I followed your method, but still has the problems below, saying that invalid usage of aggregate function of sum() and type:object
Appreciate your help. Thanks.
Brilliant, Thanks Clayton, that worked perfectly. Could I ask for another bit of advice please? Ive watched all the UIPath vid’s now but I find I am still struggling with data manipulations, is this .NET coding I need to delve deeper into on its own or something else?
UiPath works with vb.net syntax (it’s similar to C# too). Lambda and LINQ are what I find the most useful. I’m not an expert but you can look up how to do most things with Data Tables, Lists, and Arrays using these methods through online sources. The ones I use the most are Where (to filter down the data) and Select (to pull certain parts of an item).
EDIT: also, include vb.net in your online searches
I’d highly recommend throwing an if statement in your function to check if the items in “avail_balance” are in fact numbers. If it isn’t a number, change it to 0.
This way if a null value or other non-number somehow finds its way into that column, it will just convert that value to 0 instead of throwing an error (assuming you don’t want an error thrown)