Forum Discussion
JeffP25
1 year agoRegular Visitor
Dynamic File Import
I have a model that is built off of four Excel files that are stored in a network folder. The network folder contains several files that aren't associated with my model, but I need the most recent v...
Anonymous
1 year agoNot applicable
Hi, JeffP25
Maybe you can try the following expression:
let
// Step 1: Get all the files in the folder
Source = Folder.Files("FolderPath"),
// Step 2: Filter for file names that contain "X".
FilteredByText = Table.SelectRows(Source, each Text.Contains([Name], "X")),
// Step 3: Extract the identifier in the file name (assuming the format is "Identifier_Date.xlsx")
ExtractIdentifier = Table.AddColumn(FilteredByText, "Identifier", each Text.BeforeDelimiter([Name], "_")),
// Step 4: Group by identifier and take the latest file for each group
GroupAndSelectLatest = Table.Group(ExtractIdentifier, {"Identifier"}, {
"LatestFile", each Table.Sort(_, {{"Date modified", Order.Descending}}){0}
}),
// Step 5: Expand and merge the file contents
ExpandContent = Table.ExpandRecordColumn(GroupAndSelectLatest, "LatestFile", {"Content"}, {"Content"}),
ImportExcelData = Table.TransformRows(ExpandContent, (row) => Excel.Workbook(row[Content]){0}[Data])
in
ImportExcelData
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.