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 2,104 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:
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,970 Super User 2026 Season 2 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

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 430

#2
11manish Profile Picture

11manish 341 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 282

Last 30 days Overall leaderboard