Skip to main content
Community site session details

Community site session details

Session Id : NZMiHhzTDErZpWSwCZrGdD
Power Automate - Using Flows
Answered

Delete "X" of rows if table is over # (1500) of rows

Like (0) ShareShare
ReportReport
Posted on 16 Aug 2021 20:32:30 by 4

Hi Pros,

I'm stuck with the following issue and would like to know if anyone has attempted this on their own.

 

I have an Excel Online table that is updated by a Power App, I want to delete rows 2-151 each Sunday at 10pm OR IF() the number of total rows in the table exceeds 1500, delete the rows 2-500.

 

I've managed to write and Excel script to remove rows 2-500, and trigger it on Sunday @ 10pm, but I'm stuck on the above with the IF() statement, which is what I really need to happen.

 

Any help with this would be appreciated.

Thank You...

  • william_wallace Profile Picture
    4 on 17 Aug 2021 at 16:04:28
    Re: Delete "X" of rows if table is over # (1500) of rows

    @DamoBird365 Thanks so much! 

     

    I changed it up a little for my needs, this is what I'll use going forward by kicking it off with a flow every weekend.

     

    function main(workbook: ExcelScript.Workbook) 
    {
     let selectedSheet = workbook.getActiveWorksheet();
    
     let numrows = selectedSheet.getTable('Audits').getRowCount();
     if (numrows > 1500) {
     selectedSheet.getTable('Audits').deleteRowsAt(0, 500);
     }
     else { }
    
    }

     

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on 17 Aug 2021 at 06:48:47
    Re: Delete "X" of rows if table is over # (1500) of rows

    Hi @william_wallace 

     

    You could try adding logic to your office script.  I've based it on 50 and 25 and deleting the first 25 or 10 rows respectively.

     

    function main(workbook: ExcelScript.Workbook) {
    	let selectedSheet = workbook.getActiveWorksheet();
    
    	let numrows = selectedSheet.getTable('Table1').getRowCount();
    	if (numrows > 50) {
    		selectedSheet.getTable('Table1').deleteRowsAt(0, 25);
    	} 
    	else if (numrows > 25) {
    		selectedSheet.getTable('Table1').deleteRowsAt(0, 10);
    	}
    	else {}
    
    }

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1

Featured topics

Restore a deleted flow
Loading complete