Forum Discussion
ETL Options with files loop (powerquery or free?)
- 2 months ago
Hi icassiem,
You can do the looping in Power Query regardless of timestamps.
The query below will:
- Connect to a SharePoint site
- Find all CSV files
- Keep only files where the file name contains one of the keywords
- Combine all matching files into one table
- Add the source file name and source folder for audit purposes
Example
let SiteUrl = "https://yourtenant.sharepoint.com/sites/yoursite", Keywords = {"mature", "efficiency", "interna"}, Source = SharePoint.Files( SiteUrl, [ApiVersion = 15] ), FilterCsv = Table.SelectRows( Source, each Text.Lower([Extension]) = ".csv" ), FilterKeywords = Table.SelectRows( FilterCsv, each List.AnyTrue( List.Transform( Keywords, (k) => Text.Contains(Text.Lower([Name]), Text.Lower(k)) ) ) ), RemoveHiddenFiles = Table.SelectRows( FilterKeywords, each [Attributes]?[Hidden]? <> true ), TransformCsv = (FileContent as binary, FileName as text, FolderPath as text) as table => let Csv = Csv.Document( FileContent, [ Delimiter = ",", Encoding = 65001, QuoteStyle = QuoteStyle.Csv ] ), PromotedHeaders = Table.PromoteHeaders( Csv, [PromoteAllScalars = true] ), AddSourceFile = Table.AddColumn( PromotedHeaders, "SourceFile", each FileName, type text ), AddSourceFolder = Table.AddColumn( AddSourceFile, "SourceFolder", each FolderPath, type text ) in AddSourceFolder, AddData = Table.AddColumn( RemoveHiddenFiles, "Data", each TransformCsv([Content], [Name], [Folder Path]) ), Combined = if Table.RowCount(AddData) = 0 then #table({}, {}) else Table.Combine(AddData[Data]) in CombinedThe important part is this:
Keywords = {"mature", "efficiency", "interna"}This means the query will include files where the file name contains any of those words.
Examples that would be picked up:
202607_clientA_mature_export.csv clientB_efficiency_202607.csv timestamp_clientC_interna.csv
If you want separate outputs, for example one table for Mature and another for Efficiency, then create one query per keyword. But if all files should be appended into one table, the query above works.
Important: all files combined in the same query should have the same structure/columns.
And yes, you can definitly do this with powershell or Python, if you are want to do it that way, just ask we will figure out something.
And sorry if i misunderstand the problem above with PowerQuery looping.
Parchitect thank you will keep you posted
I am just concerned with the max, do we max on file date before we open the source file becuase i dont want to be max on fields that takes earlier file max value as current max date file value.
Hi icassiem,
Good instinct to check — and yes, you're safe. The max runs on the file's Date modified from the SharePoint file listing, before any file is opened. Nothing inside the CSVs is touched at that point.
The step order in the query is:
file list → filter csv/keywords/hidden → AddClientKey → LatestPerClient (metadata only, files still unopened) → AddData (only the surviving files are opened and parsed) → Combined
So older files are dropped before parsing — their rows can never leak into the result, and there's no mixing with date columns inside the data. As a bonus, fewer files get opened, so refresh is a bit faster too.
🔍Parchitect
Solutions Architect · Microsoft Fabric Specialist
💡Helpful? Kudos are appreciated.
✔️Solved? Mark as Solution so others can find it faster.
- icassiem1 month agoPost Prodigy
Parchitect v-saisrao-msft Hi, Apologies I will only be able to attempt this tomorow
- v-saisrao-msft1 month agoCommunity Support
Hi icassiem,
Checking in to see if your issue has been resolved. let us know if you still need any assistance.
Thank you.
- icassiem1 month agoPost Prodigy
Parchitect , v-saisrao-msft Prince0011 vilasdgawali Dev_Dholakia
Apologies for the delay, my proposal has been challanged by the engineers last week and been falling over my feet a little. i still have to owrk on the POC after this MVP. Different audiences (MVP = design team stakeholder, POC = Engineering prod impact)
So i started with the powerqury loop of Parchitect , it works for site but not document library, should i keep the wildcard and filter only the selected path
Bigger issue is and my mistake, its actually xlsx files with 3 tabs and all 3 per client file needs to be imported - how now?