Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
domi25
Frequent Visitor

Get the latest file from each folder on SharePoint

Hi, On SharePoint, we have several folders to which files will be added once a month, but it may happen that this is not always done. Therefore, I would like to retrieve the recently added file from each folder.

 

4 REPLIES 4
lbendlin
Super User
Super User

Is your folder list static or does that change too?

Static.

Here's how I would do it

 

- use the sharepoint folder connector

- have your list of folders (static or with a defined filter on the folder path)

- group by folder path, aggregate by max modified date  (or created date if that is more appropriate)
- for each group retrieve the file name behind the timestamp.

 

let
  Source = SharePoint.Files(
    "https://xxx.sharepoint.com/teams/PowerBIPROUserGroup", 
    [ApiVersion = 15]
  ), 
  #"Removed Other Columns" = Table.SelectColumns(Source, {"Name", "Date created", "Folder Path"}), 
  #"Filtered Rows" = Table.SelectRows(
    #"Removed Other Columns", 
    each Text.Contains([Folder Path], "Recordings")
  ), 
  #"Grouped Rows" = Table.Group(
    #"Filtered Rows", 
    {"Folder Path"}, 
    {
      {"MaxDate", each List.Max([Date created]), type datetime}, 
      {"Rows", each _, type table [Name = text, Date created = datetime, Folder Path = text]}
    }
  ), 
  #"Added Custom" = Table.AddColumn(
    #"Grouped Rows", 
    "Custom", 
    each Table.SelectRows([Rows], (k) => k[Date created] = [MaxDate])[Name]{0}
  )
in
  #"Added Custom"
christinepayton
Super User
Super User

So this isn't exactly the same, but there was a post on this just the other day where someone needed the top 3 latest by month. You could probably adapt what they're showing here for your use case: https://community.fabric.microsoft.com/t5/Power-Query/Sort-files-by-month/m-p/3653714

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.