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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Load the latest file with a filename x and the latest file with a filename y

Hello

 

I want to load and edit the latest files in a folder that have a filename containing File1 or File2.

 

The folder may contain:

File1 (created 1/1/21)

File1 (created 2/2/21)

File2 (created 1/1/21)

File2 (created 2/2/21) 

 

I want to load the latest file with a filename containing File1 and the latest file with a filename containing File2.

 

Then, each of these two files will need to be loaded to a separate worksheet named File1 or File2 respectively.

 

Is there a neat way to do that? 

 

Thanks!

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsvMSTVU0lEy1DfUNzIwAjGdMvMSiyqVYnWQZY1wyBoBhYwIyOIy2RgoZExAFsPkWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FileName = _t, ModifiedDate = _t, Content = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"FileName", type text}, {"ModifiedDate", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([FileName] = "File1" or [FileName] = "File2")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"FileName"}, {{"AllRows", each _, type table [FileName=nullable text, ModifiedDate=nullable date]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {"AllRows", each Table.Max(_, "ModifiedDate", Order.Descending)}),
    #"Expanded AllRows" = Table.ExpandRecordColumn(Custom1, "AllRows", {"ModifiedDate", "Content"}, {"ModifiedDate", "Content"})
in
    #"Expanded AllRows"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

1 REPLY 1
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsvMSTVU0lEy1DfUNzIwAjGdMvMSiyqVYnWQZY1wyBoBhYwIyOIy2RgoZExAFsPkWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FileName = _t, ModifiedDate = _t, Content = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"FileName", type text}, {"ModifiedDate", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([FileName] = "File1" or [FileName] = "File2")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"FileName"}, {{"AllRows", each _, type table [FileName=nullable text, ModifiedDate=nullable date]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {"AllRows", each Table.Max(_, "ModifiedDate", Order.Descending)}),
    #"Expanded AllRows" = Table.ExpandRecordColumn(Custom1, "AllRows", {"ModifiedDate", "Content"}, {"ModifiedDate", "Content"})
in
    #"Expanded AllRows"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.