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 / 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,811 Super User 2024 Season 1
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,362 Super User 2025 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 Super User 2025 Season 2 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

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 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard