how to sum rows of a specific column from a collection
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-10-19 06:53 PM
Hello everyone!
I'm trying to get the total amount from a column of a Collection without looping (with Collections of 5000 Rows memory issues could appear). The only way to do this is by using a code stage, but i'm kind of lost on this...
For example: A collection with 1200 Rows I want to get the total amount of "X" Column:
X Column is text type, so each value I have to convert it to integer ...
what i tried was using LinQ with this code that i found on internet;
When I run the action it throws an error Internal : Exception: Object reference not set to an instance of an object..
I think I'm missing something with the code ( I dont know VB :c ) or the reference but I dont know what.
Is there any better way to accomplish this? What am i doing wrong?
------------------------------
Daniel Sanhueza
Analyst
Deloitte
America/Santiago
------------------------------
I'm trying to get the total amount from a column of a Collection without looping (with Collections of 5000 Rows memory issues could appear). The only way to do this is by using a code stage, but i'm kind of lost on this...
For example: A collection with 1200 Rows I want to get the total amount of "X" Column:
X Column is text type, so each value I have to convert it to integer ...
what i tried was using LinQ with this code that i found on internet;
Dim total = dt.AsEnumerable().Sum(Function(t) t.Field(Of Integer)("X"));
The Code Options was this;

When I run the action it throws an error Internal : Exception: Object reference not set to an instance of an object..
I think I'm missing something with the code ( I dont know VB :c ) or the reference but I dont know what.
Is there any better way to accomplish this? What am i doing wrong?
------------------------------
Daniel Sanhueza
Analyst
Deloitte
America/Santiago
------------------------------
Daniel Sanhueza
RPA Professional Developer
Deloitte
RPA Professional Developer
Deloitte
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-10-19 01:05 AM
You can also use dt.Compute("Sum(FieldName)","") without LinQ.
Not sure why LinQ is not working for you, but I don't like that field type Of Integer. Number type of collection is decimal.
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------
Not sure why LinQ is not working for you, but I don't like that field type Of Integer. Number type of collection is decimal.
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------
