Forum Discussion

domi25's avatar
domi25
Frequent Visitor
2 years ago

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

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        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"