web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Remove first and last ...
Power Automate
Answered

Remove first and last two rows from DataTable or Excel on Web Data Extract

(0) ShareShare
ReportReport
Posted on by 13

Hey Guys,

 

I have a 'Extract Data From Web Page' process which is outputting the data (at the moment) to a DataTable. I have a For Each which processes each row with a number of IF statements BUT it's taking too long and so I need to make my process more efficient.

 

Looking at the DataTable, the first and last two rows contains data which isn't being actioned by any IF statement and by removing it, I can make my process about 30% more efficient.

 

So, my question is - How do I remove the first and last two rows from my DataTable?

 

As I don't necessarily need it as a DataTable - it  can output to Excel instead where I can use the 'Delete row from Excel worksheet' option (which seems the easier path) but any ideas what I'd put as a variable (or otherwise) when specifying which row to delete?

 

As always, any help would be most welcomed! 

 

Thanks. 

  • Verified answer
    VJR Profile Picture
    7,635 on at

    Hi @Walker999 

     

    For a datatable, get the number of rows of the datatable and use it in the delete.

     

     

    VJR_1-1664017957873.png

     

     

    This will delete the last row and if you do it one more time it will delete the second last.

    You have to subtract 1 from the Count because the index starts from 0. If total rows are 4 as above then you need to delete row #3.

     

    For deleting the first row use 0 as the index.

     

    VJR_0-1664017922959.png

     

     

     

     

    For Excel:

    If you do not have this new action in your version of Power Automate Desktop and if you are not able to update for some reason, then do the same inside Excel -> Use "Get First free row/column..." action to get the total number of rows and use that to pass into the "Delete row from Excel" action.

     

     

  • Walker999 Profile Picture
    13 on at

    The RowsCount - 1 is exactly what i needed! 

     

    Thanks for your help

  • HarriH Profile Picture
    8 on at

    Thanks for explaining the background for the .RowsCount -1 variable.

    I was using this command but could not find the explanation why -1.
    The explanation you gave was clear and concise. Kudos!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 273 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 235

#3
David_MA Profile Picture

David_MA 172 Super User 2026 Season 2

Last 30 days Overall leaderboard