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 / Power Automate: Retrie...
Power Automate
Suggested Answer

Power Automate: Retrieve Latest SharePoint Folder (5000+ items) Safely

(0) ShareShare
ReportReport
Posted on by 4

Hello, Please read to the end and I am waiting for your feedback!

I’m building a scheduled Power Automate Cloud flow to automatically:

  1. Go to SharePoint site

    https://pepsico.sharepoint.com/teams/iSCPRussia

  2. Library: OMP

  3. Folder: Reporting

  4. Inside Reporting there are ~5000 subfolders

    Each folder name format: yyyyMMddHHmmss

  5. Inside each folder there is one Excel file.

Flow logic:

Get files (properties only) → retrieve folders inside Reporting

Filter Query: FSObjType eq 1

Top Count: 5000

  • Compose → get latest folder name using:

    last(body('Get_files_(properties_only)')?['value'])?['Name']
  • Get files (properties only) → inside latest folder

    Limit entries to folder:

    concat('Reporting/', outputs('Compose'))

    Filter Query:

    FSObjType eq 0

    Top Count: 1

  • Get file content → using:

    first(body('Get_files_(properties_only)_1')?['value'])?['Identifier']

Issue:

Get file content fails with error:

The resolved string values for the following parameters are invalid, they may not be null or empty: 'id'

Meaning the Identifier returned from previous step is null.
 

🔹 Objective

Create an automated Power Automate Cloud flow that retrieves the latest daily report from a SharePoint document library and uploads it to a structured Microsoft Teams folder with standardized naming.

🔹 Business Logic

The flow must:

1️⃣ Scheduled Execution

Run automatically every day at 10:05 AM.

2️⃣ Locate Latest Timestamp Folder

In a SharePoint document library:

Navigate to the folder: Reporting

Inside this folder there are ~5000 subfolders

Each subfolder name follows a strict timestamp format:

yyyyMMddHHmmss
Example:
20260304043733

The flow must dynamically identify the latest created folder, based on this timestamp naming convention (highest lexical value).

3️⃣ Retrieve Report File

Inside the identified latest timestamp folder:

There is one Excel file

File naming pattern:

 

 

yyyMMddHHmmssStock report (dos) 10 daysOPR.xlsx
Example:
20260304043733Stock report (dos) 10 daysOPR.xlsx
The flow must:
  • Open the folder

  • Locate this file

  • Retrieve its content

4️⃣ Rename File

After retrieval, the file must be renamed using standardized business format:

dd.MM.yy Stock report (dos) 10 daysOPR.xlsx
Example:
04.03.26 Stock report (dos) 10 daysOPR.xlsx
5️⃣ Upload to Microsoft Teams

The renamed file must then be uploaded to the Teams channel document structure:

Documents
→ General
→ Quota management
→ Проекция_стоков_DAIRY
→ MM. MonthName
Example:
03. March
The file must be placed inside the corresponding monthly folder.

🔹 Key Technical Considerations

  • The Reporting folder contains approximately 5000+ subfolders.

  • The solution must dynamically identify the latest folder.

  • No hardcoded folder names.

  • Must be production-safe and reliable.

  • Must handle large SharePoint libraries without threshold failures.

Key Questions:

  1. Is there a recommended production-safe pattern to retrieve the latest folder in a SharePoint library with 5000+ items?

  2. Is last(body(...)) reliable when no Order By is used?

  3. Could threshold behavior cause incomplete results even when Top Count is set?

  4. What is the best practice to retrieve the latest folder and its file in large libraries?

    Thank you.

Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,716 Super User 2026 Season 1 on at
    1. SharePoint is not the right tool for what you are trying to accomplish. You can make it work but it will be very, very slow
    2. no
    3, yes. Use much smaller page sizes (500 or less)
    4. Use the Graph API directly. Or use a different storage hierarchy  (one folder per day, for example)
  • deepakmehta13a Profile Picture
    369 on at

    Hi,

    You raised some very good questions. When working with SharePoint libraries that contain thousands of folders or files, it is important to design the flow in a way that avoids ordering issues and the SharePoint list threshold.

    1. Is there a recommended production-safe pattern to retrieve the latest folder in a SharePoint library with 5000+ items?

    Yes. A production-safe approach is to let SharePoint return only the latest item instead of retrieving all folders and processing them in Power Automate. This can be done using OData sorting with Top Count in the Get files (properties only) action.

    For example:

    Filter Query
    FSObjType eq 1

    Order By
    Name desc

    Top Count
    1

    Since your folder names follow a timestamp format like yyyyMMddHHmmss, sorting by Name descending will return the newest folder directly. This avoids retrieving thousands of folders and is much safer for large libraries.

    2. Is last(body(...)) reliable when no Order By is used?

    No, it is not reliable. SharePoint does not guarantee the order of items returned by the Get files (properties only) action unless an Order By clause is specified. Without ordering, the result set may appear arbitrary, so using last() or first() may not consistently return the newest folder.

    3. Could threshold behavior cause incomplete results even when Top Count is set?

    Yes. SharePoint libraries have a list view threshold of 5000 items. Even if Top Count = 5000, SharePoint may still apply internal filtering or indexing rules. If the query is not optimized, the flow may not retrieve all items or may return inconsistent results.

    Using Filter Query + Order By + Top Count ensures SharePoint performs the sorting server-side and only returns the required result.

    4. What is the best practice to retrieve the latest folder and its file in large libraries?

    A common and reliable pattern is:

    1. Use Get files (properties only) to retrieve the latest folder

    Filter Query
    FSObjType eq 1

    Order By
    Name desc

    Top Count
    1

    1. Use another Get files (properties only) action targeting that folder to retrieve the file inside it

    Filter Query
    FSObjType eq 0

    Top Count
    1

    1. Use the returned Identifier with Get file content or any subsequent actions.

    For very large libraries or more advanced scenarios, another option is to use the Microsoft Graph API to query the document library. Graph supports server-side sorting and querying, which can sometimes provide more flexibility and better performance when working with large datasets or complex folder structures.

    This approach ensures that SharePoint (or Graph) handles the filtering and sorting efficiently, rather than retrieving thousands of items into the flow.

    Hope this helps.

  • AM-04031200-0 Profile Picture
    4 on at
    I can't find action - Microsoft Graph API ? 
    maybe it has premium version?
  • LB-04112000-0 Profile Picture
    50 on at
    You run HTTP actions. And yes, these require a premium license.
  • AM-04031200-0 Profile Picture
    4 on at
    I don't have a premium license. Can I do without this premium license?
  • Suggested answer
    deepakmehta13a Profile Picture
    369 on at

    Hi,

    You might still be able to implement this without a premium license. Using the Microsoft Graph API would normally require the HTTP action, which is a premium feature in Power Automate, so that option may not be available in your case.

    However, since your folder names follow a timestamp format (yyyyMMddHHmmss), you could try using SharePoint’s built-in sorting to retrieve the newest folder instead of relying on Graph API.

    One possible approach is configuring the first Get files (properties only) action like this:

    Filter Query
    FSObjType eq 1

    Order By
    Name desc

    Top Count
    1

    Because the folder name itself contains the timestamp, sorting by Name descending should return the latest folder.

    After that, you could use another Get files (properties only) action to retrieve the file inside that folder:

    Limit entries to folder
    concat('Reporting/', first(body('Get_files_(properties_only)')?['value'])?['Name'])

    Filter Query
    FSObjType eq 0

    Top Count
    1

    Then pass the returned Identifier to Get file content.

    This approach might help avoid retrieving thousands of folders and could work using only the standard SharePoint actions in Power Automate, without requiring a premium connector.

    If this approach helps resolve your issue, please consider marking the response as Verified, as it may also help others facing a similar scenario.

    Hope this helps.

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 464

#2
Haque Profile Picture

Haque 431

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard