Count the number of records satisfying a particular condition



I have a requirement in which I need to take the no of records in excel satisfying a particular condition.

I am using data table for this. Can anyone give me example for this?

How to apply filter in this case?

Thanks and Regards,



you can use DataTable.Select method here. I will return an array of DataRows that match your particular condition.

myMatches = myDT.Select(“Age > 20”)
myMatches.Count, returns the number of these records.




.Count from Linq is doing exactly that.

Example mailList.Count(Function(m) m.Subject.Contains(“UiPath”) AndAlso m.Body.Contains(“Download”))

m being an element of your collection.

You can recplaces the Contains there by any expression returning a boolean.

In terms of Datatable you can use dt.AsEnumerable so your datatable will be converted to IEnumerable(Of Datarow) and you will be able to use Linq on them.

dt.AsEnumerable.Count(Function(r as DataRow) r(“Column1”) = “25”)

As mention Datatable.Select is also a good option depending on what you want to achieve but more generally Linq will give you more options.