Adding only the last 5 rows of datatable to queue

Hello everyone,

I am doing a pdf scraping case and I am stuck. I have a datatable with 6 columns. (Invoice number, vendor etc.) and I have to add the last 5 rows of this datatable to the queue.

How should I approach this?

I am new to UiPath so explicit answers would be the great. Thanks!

Hi @idil.konca

Welcome to Uipath community

How about this expression

DtBuild.asenumerable.reverse().take(5).copytodatatable

image

1 Like

Hi @idil.konca

Check out the XAML file

TakeLast5RecordFromDT.xaml (11.3 KB)

Regards
Gokul

1 Like

wow, such quick response! Thank you. This is actually very useful. I have one more question, how to keep the first row as it is and add the last 5 under that first row?

You are taking about the Header ah ? @idil.konca

yes indeed. But my code does not work if I select the “use first row as column headers” inside datatable, I dont know why. That is why I am trying to find a workaround :slight_smile:

Hi @idil.konca

Can you share the sample excel file.

Do you have Duplicate column Header in the excel ?

I am a new user thus I cannot upload just yet I suppose :frowning: But I have regular 5 columns as;

  • Invoice_No
  • Tax_ID
  • Explanation
  • Total_Value
  • Currency
  • Date

HI @idil.konca

While Read the excel file enable this Add Header in the properties panel

While adding the data into the queue it will take with the column names

Regards
Gokul

I actually read a pdf, write into text file, do some manipulations via invoke code, then get the output of code (datatable) and use it as an input. After all these I write it inside an Excel file.

Hi @idil.konca

Before writing into the Output value, You keep the column name has a template and append the output value in that excel.

After that use LINQ expression to take last 5 record from the excel.

Regards
Gokul

2 Likes

Thank you @Gokul001 !

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