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 / Problem deleting all r...
Power Automate
Answered

Problem deleting all rows in an Excel table with Power Automate due to duplicate values

(0) ShareShare
ReportReport
Posted on by 8

Hi everyone,


I’m trying to create a Power Automate flow to completely clear an Excel table, but I’m running into an issue with duplicates.
Here’s what I’ve done so far:


I have an Excel table with multiple columns, and some columns contain duplicate values (which is expected). I use “List rows present in a table” to read all the rows. For each row, I use “Delete a row”, specifying one column as the Key Column and its value as the Key Value.


The problem: the first row with a given value deletes fine, but when there are duplicates, the action fails. Essentially, when the flow tries to delete a second row with the same value, the Key Value no longer exists → error.
I’ve tried changing the order of iteration and filtering the data before deleting, but that doesn’t solve the problem.
So I’m looking for a reliable way to completely clear an Excel table, even if it contains duplicates, either:


A simple way to delete all rows at once.
A robust way to do it while still using “List rows” → “Delete a row”.


Thanks in advance for your help!

Categories:
I have the same question (0)
  • Suggested answer
    Tomac Profile Picture
    4,053 Moderator on at
     
    In your spreadsheet, you should add a column for Index and set it as an Index column so the values are all unique. This can then be used for your key/value pairs to delete the rows.
     
    When working with tables in Excel like this, you should always have an Index column to ensure there are no issues.
  • Suggested answer
    abm abm Profile Picture
    32,985 Most Valuable Professional on at
    Hi
     
     
    Below is the Filter query I used under the List Rows
     
     
    Then under the Delete row step I mapped Key column as Name the key value from the list rows
     
     
     
    This works for duplicate rows. I have tested this and got the expected results.
     
    Thanks
  • RE-13111647-0 Profile Picture
    8 on at
    Hi @Tomac, thanks for your reply.
    The problem is that I have a specific output format to adhere to. If I add an index column, how do I delete that column using Power Automate? The only option available is to delete rows.
  • RE-13111647-0 Profile Picture
    8 on at
    Hi @abm abm, thanks for your reply. The problem with your filter is that it will only take rows where the value 'Ajith' is in the 'Name' column, right? What I'd like to do is filter to remove any duplicate values ​​in the list rows. If I can get my table to contain only unique values ​​in the 'Name' column, that will work for deletion.
  • Suggested answer
    Tomac Profile Picture
    4,053 Moderator on at
     
    You can hide columns in the Excel file directly without needing to delete them.
     
    Alternatively, to remove duplicate values from an array, feed that array into the union() function as both arguments in a Compose action and then use the output of that Compose as the working array. For example, if I have duplicate rows in my Excel data (fully duplicate rows, not duplicates of a single column), I would put this in a compose:
    union(outputs('List_rows_present_in_a_table')?['body/value'],outputs('List_rows_present_in_a_table')?['body/value'])
     
    If I wanted to remove duplicates from a single column, first I'd need to use a Select action to get an array with only that column:
     
    And feed the output of that Select into my union() function.
     
     
  • Verified answer
    rzaneti Profile Picture
    4,491 Super User 2026 Season 1 on at
     
    If your organization doesn't restrict its usage, you can go with Office Scripts for this task. No loops, no worries with key columns - just clear a table with a single action and that's it.
     
    I'm sharing some blogs that I posted about Office Scripts, so you can have more context about it, but as a short description, it works like a VBA for Excel on the Web and it can be initialized by Power Automate:
    - Sending values from Power Automate to Excel with Office Scripts: https://digitalmill.net/2024/01/17/sending-values-from-power-automate-to-excel-with-office-scripts/
    - Debugging and accessing Office Scripts outputs with console.log: https://digitalmill.net/2024/09/09/debugging-and-accessing-office-scripts-outputs-with-console-log/
     
    Here is the table that I will use as example, containing 100 entries and many repeated values in both columns:
     
    First thing to do is to create your Script, which will look like this. Go to Automate tab and click New script:
     
     
    Make sure to replace the text in green ("Table 2") for the actual name of the table that you want to clear:
     
     
    function main(workbook: ExcelScript.Workbook) {
        
        let table = workbook.getTable('Table2')
        
        table.getRangeBetweenHeaderAndTotal().delete(ExcelScript.DeleteShiftDirection.up)
    
    }
     
     
    Just these two lines of code are enough. You will basically access the table object (line 3) and then delete all entries (line 5). 
     
    After saving the Script, go to Power Automate and add a Run Script action, informing the file where you want to run it and the script to be used (the one that you just saved):
     
     
    That's all: you can now run the flow (for these 100 records, it took 8 seconds to run):
     
    And once you're back to Excel, the table will now be empty:
     
     
    Let me know if it works for you or if you need any additional help!
     
    If this solved your issue, please mark it as Accepted Answer.
    👍 If it helped, feel free to give it a like!

    🌐 Explore more Power Platform content on my Website or on my ▶️ YouTube
    💼 Find me on LinkedIn
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 711

#2
Vish WR Profile Picture

Vish WR 691

#3
Haque Profile Picture

Haque 525

Last 30 days Overall leaderboard