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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Apply to Each to delet...
Power Automate
Unanswered

Apply to Each to delete duplicates

(0) ShareShare
ReportReport
Posted on by

I have created a basic flow to take the response from an MS Form and create a new item in a SharePoint list.

 

When a new one is added I want it to go through and check each item's date and if it's more than 7 days it should be deleted. I can't seem to get this working, any help would be appreciated.

 

Screenshots attached

Categories:
I have the same question (0)
  • Matthy79 Profile Picture
    4,180 Super User 2024 Season 1 on at

    Hello @DylanB02 

     

    If you want to apply to each item, you first have to get all the items. You can only use “apply to each” for arrays. Your input is a number.

  • v-yetonggu-msft Profile Picture
    on at

    Hi @DylanB02 ,

    Do you want to when new items are added, go through and check the date of each item, and if it's older than 7 days, delete it?

    If so, I have a test for your reference.

    In my scenario:

    vyetonggumsft_0-1695634212212.png

    vyetonggumsft_1-1695634212217.png

    vyetonggumsft_2-1695634212222.png

     

    formatDateTime(items('Apply_to_each')?['Created'],'yyyy-MM-dd')

     

    vyetonggumsft_3-1695634212223.png

     

    addDays(outputs('Create_item')?['body/Created'],-7,'yyyy-MM-dd')

     

    vyetonggumsft_4-1695634212229.png

    Best Regards,

    Sunshine Gu

  • Matthy79 Profile Picture
    4,180 Super User 2024 Season 1 on at

    The solution of @v-yetonggu-msft is correct but you should filter during “get items”. That way you will loop less items and don’t need the condition inside the apply to each.

  • DB-17060835-0 Profile Picture
    on at

    Hi @v-yetonggu-msft,

     

    Thanks for your help with this, it ran successfully.

     

    I have tried to add an item in with the date more than 7 days ago but when I add another entry it isn't removing that submission but still showing as flow ran successfully

     

    I'm not sure whether it is to do with the "date" column on SharePoint and the formatDate expression i have used using the same format, "dd-MM-yyyy".

     

    Added some more screenshots.

     

    Thanks

  • v-yetonggu-msft Profile Picture
    on at

    Hi @DylanB02 ,

    Could you please set the formatDateTime on both sides of the condition action to 'yyyy-MM-dd'?

    Please show your full flow.

    Best Regards,

    Sunshine Gu

     

  • DB-17060835-0 Profile Picture
    on at

    See below

    DylanB02_1-1695637322350.png

    DylanB02_2-1695637353443.png

    formatDateTime(items('Apply_to_each')?['Created'],'yyyy-MM-dd')
    addDays(outputs('Create_item')?['body/Created'],-7,'yyyy-MM-dd')

    DylanB02_3-1695637477937.png

     

     

     

  • DB-17060835-0 Profile Picture
    on at

    And just for your reference, this is how it comes through on SharePoint

     

    DylanB02_4-1695637751710.png

     

  • v-yetonggu-msft Profile Picture
    on at

    Hi @DylanB02 ,

    Attention:

    1)Please check in the ID is Get items Dynamic content.

    vyetonggumsft_0-1695638253460.png

    2)Please check in the actual creation time of the item.

    vyetonggumsft_1-1695638359020.png

    vyetonggumsft_2-1695638395072.png

    vyetonggumsft_3-1695638462055.png

    Best Regards,

    Sunshine Gu

  • DB-17060835-0 Profile Picture
    on at

    Yes, the ID is set to the "Get Items" one.

     

    As for the second step, are you asking me to create a new column called CreateDate? I have a date column already for this.

     

    Thanks

  • v-yetonggu-msft Profile Picture
    on at

    Hi @DylanB02 ,

    You do not create CreateDate columns,

    Could you please show you created column.

    vyetonggumsft_0-1695640657405.png

    vyetonggumsft_1-1695640683385.png

    Best Regards,

    Sunshine Gu

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard