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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
gvg
Post Prodigy
Post Prodigy

Extracting a list of most recent files in all folders

Hi,

 

I am looking for the way to transform only recent files in each folder, containing different number of files. Example folder/file structure:

 

MainFolder
    - Folder1
             File1     2020-01-06
             File2     2020-01-09
   - Folder2
            File6     2020-01-04
            File7     2020-01-03
            File5     2020-01-05
   -  ......

 

I need to process all the recent files in each subfolder of MainFolder, i.e. files:

File2     2020-01-09

File5     2020-01-05

 

How would I do that?

Thanks.

2 ACCEPTED SOLUTIONS
artemus
Microsoft Employee
Microsoft Employee

Add the following custom step after your Folder.Files step:

 

= Table.Group(Source, {"Folder Path"}, {{"LastestFile", each Table.Max(_, "Date modified")[Content], type binary}})

View solution in original post

artemus
Microsoft Employee
Microsoft Employee

Oops, sorry about that... should really double check that it works first.

 

It should be:

 

= Table.Group(Source, {"Folder Path"}, {{"LastestFile", each Table.Max(_, "Date modified")[[Content], [Name]], type record}})

 

View solution in original post

6 REPLIES 6
artemus
Microsoft Employee
Microsoft Employee

Add the following custom step after your Folder.Files step:

 

= Table.Group(Source, {"Folder Path"}, {{"LastestFile", each Table.Max(_, "Date modified")[Content], type binary}})

Yep, it works. Thanks @artemus !

Can you show how to add Name column to the result. Tried this one, but it returns back all the files:

 

Table.Group(Source, {"Folder Path", "Name"}, {{"LastestFile", each Table.Max(_, "Date modified")[Content], type binary}})

 

artemus
Microsoft Employee
Microsoft Employee

Sure, just change [Content] to [[Content,Name]]. Then expand the record column.

 

 

Table.Group(Source, {"Folder Path"}, {{"LastestFile", each Table.Max(_, "Date modified")[[Content, Name]], type binary}})

 

 

  

Does not want to work. Complains about comma after Content 😞

artemus
Microsoft Employee
Microsoft Employee

Oops, sorry about that... should really double check that it works first.

 

It should be:

 

= Table.Group(Source, {"Folder Path"}, {{"LastestFile", each Table.Max(_, "Date modified")[[Content], [Name]], type record}})

 

Thanks @artemus  ! Now everything in order.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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