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 / Automated file deletio...
Power Automate
Answered

Automated file deletion based on user set date and a user set code

(0) ShareShare
ReportReport
Posted on by 8

Hi,

 

For limiting our data retention, we want to set up Power Automate to delete specific types of files after a certain period, but without reference to the file created date (we need to set our own date for some files). Thanks in advance for any assistance you could provide.

 

Essentially, we need to delete files based on two conditions:  

 

  1. Date (eg, over 3, 5, or 15 years) and
  2. Our document code (eg, delete “ABC” type files, but not "XYZ")

Putting that together, the command would be, for example: delete any file with the code "ABC" that is more than 1095 days since its "start date".

 

A critical complication to this is we cannot use the standard file created date because the date the file was created may not be the date we need to use as the reference point (eg, the paper document came into existence on 1 October, but the electronic scan was created on 1 December, so the created date is 2 months later than what we require). This is one illustration; there are other reasons we are likely to require the ability to select our own file date.

 

In share point, we have created new columns for “Doc Code” and “Start date”. For example:

 

SHR_0-1651058802732.png

The columns above are something like the columns we wish to use in the power automate delete flow. Is anyone able to suggest how we can set up a power automate to delete only “ABC” code documents after a set time period, eg, 3 years / 1095 days, but (critical) using our own selected dates for the files?

 

Thanks again,

Categories:
  • Verified answer
    ScottShearer Profile Picture
    25,331 Most Valuable Professional on at

    @SHR 

    You can use a recurrence trigger and set it to run once a day

    Add a Get Files, properties only action and add a filter query

    Your filter query should look something like this:

    DocCode eq 'ABC' and StartDate eq 'addDays(utcNow(), -1095,'yyyy-MM-dd')'

     

    Loop through everything returned by Get Files (properties only)  and delete each one.

     

    Note the following:

    • Everything in red is part of an expression and must be entered in the expression window
    • You need to use the  SharePoint internal column names for Doc Code and Start Date.  Internal names do not have spaces and may/may not be DocCode and StartDate
    • The single quotes are not optional

    Let me know if you need additional help.

    image.png

    UPDATE:

    I should have selected Identifier in my delete File action rather than ID - sorry...

    image.png

     

  • SHR Profile Picture
    8 on at

    Thanks for your quick response. Appreciate it.

     

    The issue we appear to be stuck at is finding the correct internal column names for Doc Code. “DocCode” gave a run error. We tried “Doc_x0020_Code”, which ran without error, but did not delete files in the sandbox, ie, appears to run without the desired effect. 

    The online guides on locating the internal name tend to rely on the list, but we have created no lists in this sandbox. 

    Is there another simple way to locate the internal column name?

  • ScottShearer Profile Picture
    25,331 Most Valuable Professional on at

    @SHR 

    The easy way to find the internal name of your column is as follows:

    1. Go to the SharePoint library and click on library settings
    2. Click on the column name to go to the column configuration screen
    3. Look at the URL of the page you are on
      1. The internal name will be towards the end of the URL after Field=

    Sometimes the internal name is different than you might expect.

    Here is an example (your internal name may be different):

    image.png

    If you are still having issues, please post a screen shot of your filter query and of the part of the URL containing Field=

     

     

     

  • SHR Profile Picture
    8 on at

    Thanks again for your response, Scott.

     

    I followed your process. It appears we are using the right internal name, eg:

     

    De-identified Screenshot (1).png

    De-identified Screenshot (2).png

    De-identified Screenshot (3).png

    De-Identified Screenshot (4).png

     

    I’m going to reach out to our IT dept as they may be preventing our action in Power Automate.      

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
Mohsin Ali Profile Picture

Mohsin Ali 423

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 177

Last 30 days Overall leaderboard