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 / Get the latest 5 files...
Power Automate
Suggested Answer

Get the latest 5 files inside "List Files in folder" onedrvice action

(1) ShareShare
ReportReport
Posted on by 1,950 Season of Giving Solutions 2025
I have the following action to "List the Files inside a Folder":-
 
 
 
 
now how i can only get the latest (based on the modified date) 5 files?
 
i used this formula to get the id of the latest file:-
 
last(sort(outputs('List_files_in_folder_2')?['body/value'], 'LastModified'))?['Id']
 
but how i can get the 5 latest files? i can not find a way to do LastN()?
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
    Hi,
     
    So you need to do 3 things
    1) sort them by LastModified
    2) reverse it
    3) use the Take expression to take the first 5 based on step 2
     
    Now you have the last 5
     
    So in my example, I did this
     
    And my Sort/Reverse/Take is here
    take(reverse(sort(outputs('List_files_in_folder')?['body/value'],'LastModified')),5)
     
  • Suggested answer
    Sayan Profile Picture
    818 Moderator on at
    Hey,
     
    Solution:
     
    Step 1:
     
    Initialize a variable which is an Array type.
     
    Get the files from the folder
     
    Step 2:
     
    Set a Variable by using the following expression to get the 5 files.
     
    take(reverse(sort(outputs('List_files_in_folder')?['body/value'],'LastModified')),5)
    Workflow:
     
     
    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Thanks,
    Sayan Patra | RPA Developer
     
    If my suggestion helps you, please gives it a Thumbs up and Marks as a Solution. Which motivates to solve more problems.

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 664

#2
Haque Profile Picture

Haque 460

#3
Valantis Profile Picture

Valantis 357

Last 30 days Overall leaderboard