Linq query for getting number of records in columns

I have given the input and output datatables. The below is my requirement. Could anyone please help me witht eh LINQ query for this.

  1. For String type columns (“Name” and “Place”) ,I want to get the number of records for each column in different datatable excluding the whitespaces or null.

  2. For Numeric type columns (“Age” and “Marks”), I want to get the sum of all column values excluding any character values. In case of any characters, i will have to just mention ERROR.

Input:
DT

Output:
DTout

Please let me know if there is any other easy way too.

@ppr - Hope, you would be able to help me on this pls.

@Sugumar8785

You should use DataTable Aggregate functions to do this. Please download below package from either Uipath Connect or through Manage packages and then use DataTable Aggregate functions.

2 Likes

@Sugumar8785
Can do sometihing new and different but more supporting you on learning and getting independent?

2 Likes

I have been trying it. But couldn’t get it yet. I will try. Thanks,

If you are not familiar with linq, just dont use it… Do the way you know how, should be quite easy to simply use a for each row with a few if conditions and count every column…

2 Likes

@Sugumar8785
some words were lost from my post above, as I was on the rush. But I do think similar as mentioned in the other posts. You will learn and get more when you will decompose the work into smaller tasks. And you can explore different concepts and techniques. This will let you grow. So coming back to my question: are you interested on a different guidance?

If yes so do first thing:
explore the different ways on how to do aggreagations (e.g. sums)

  • the activity as mentioned by @lakshman
  • low level implementation with for each as mentioned by bcorrea
  • the select /compute approach given with the methods from the datatable API
  • and for sure the LINQ way

so we could guide you on implementing these small tasks and will help you on combining it to a solution.

Let us know your feedback

2 Likes