How to get Top N rows from a DataTable in UiPath

Using DataTable is a major part of any automation process.

How does this help in real-time scenarios?

When you stored all the required data in a DataTable from csv/xlsx.

At a certain point in time, you require to process top N rows from the whole DataTable.

Let’s assume a scenario where you have to pick values from DataTable and search in Google and write it back to excel.

But there is huge data so you need to process them by taking top N rows. There might be several reasons why you have to do this.

One among them is when you are automating continuously the responsiveness of that application (here it is Google).

Now let’s see how we can achieve this:

First let us build a DataTable by using Build DataTable Activity.


Here is our DataTable which consists of 3 Rows and 2 Columns.

Now i want to take only 2 Rows from this DataTable. you can achieve that by using the below expression :


Here TopNrecordesDT is a DataTable variable where I am storing the top n records from the current DataTable DT.

Take(2) – it allows you to set the number of Rows that you want to get from DataTable.

Here it is Top 2 Rows.

The output looks like this:


We got Top 2 Rows from the original DataTable which has 3 Rows.

This is how you get Top N rows from a DataTable in UiPath.

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *