How to get the number of rows in a particular Column in Datatable

Suggest a expression to get it

1 Like


Welcome to UiPath community

Hope this would help you

TestDt.AsEnumerable().Select(Function(x) x.Field(Of String)(“YourColumnName”).Trim).ToArray().Where(Function(y) Not String.IsNullOrEmpty(y)).ToArray().Count

Cheers @Viswanathan_M

Hi @Viswanathan_M, welcome to the Community.

You can convert the specified row into an array and take the count of the elements, which gives the number of rows present in the column.

dt.AsEnumerable().Select(Function(row) row("Column1")).ToArray().Count()

Hope this helps,
Best Regards.

Hi @Viswanathan_M ,

Ideally all the columns in a Datatable will have the same row count, So we directly use the below :


But if the intention is to get only the Non-Empty rows Count in a column, then we can use the below Expression :


The above is also when you only have empty values in the end of the column.

Got the Solution its working fine Thanks Palaniyappan.

1 Like

Glad it got resolved @Viswanathan_M

I am interested in Learning this expression, from where did i learn this expression.

1 Like

Have a view on this for more details on accessing datatable

Cheers @Viswanathan_M

1 Like

Hi @Palaniyappan

Thanks for providing solutions on forum.
This expression is not working for empty rows in data table, mean count 0 it’s not working.


First check whether the datatable has records in it before using the linq query with a simple IF condition


have to check only if that particular column has records. because other columns having records and hence data table will obviously say that has records.

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