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.
Good day,
I need help please, i have no tools and only powerbi currently with my F2/F4 Fabric subscription only apporved for august and evlopment targeted for end of November, but now stakeholder wants an mvp to show exec memebers to get the appetite going using an existing report with a full manual operation. The product has an export per client of which i will ingest once i start with fabric and loop, but the stakeholder wants to monthly export per clinet and dump the csv into a folder directlory which is timestamped. The report should pickup theres a new source file and loop through the existing files as the source file for the powerbi.
the option i have is to complie the infor all together for one big file per month and combie or take latest timesamp for 25 lients and paste it and dont say im doing it manually for the next 5 months or can powerquery do this or anyother free source tool untill im up and runningm, the stakeholder is aware this is interim. Or even using powerquery or powershell to merge loop all the the files based on it source being "Mature_client***.csv" to say combine all the mature files to append as one and then in puwerbi powerwuery i transform and clean it, i cant use fabric trial as this is only a month or can it be done with python and i run the notebook manually monthly from my pc or is the a free etl i could use to do this etc
Sorry i know its a crappy ques. I am just thinking out loud because i have no idea and dont want to lose the audience now that theres an apetite until i have fabric up and running
Regards