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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dnguyen67
Frequent Visitor

Iterate through folder and subfolders to get cvs data

Is it possible to iterate through a folder and subfolders as below, and combine targeted csv files into one table? 

 

for example, I want to get all data (from day 1 to day 30) in one Folder_Jan2019, then iterate through other months folders as well, and combine them into a table. Possibly also iterate through Folder_2019, Folder_2020,etc. and combine all data from years as well.

 

dnguyen67_0-1646414127577.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

If all of the files in the different subfolders have the same structure, you can use Folder.Files, and then the transform query will help you combine them.  If there are differently structured files in each folder, I would replace Folder.Files with Folder.Contents, which will give you a view of the different folders, into which you can drill down into the individual files.

 

--Nate

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Unless you construct some user-defined functions in PQ to traverse all folders and sub-folders, there's no functions out-of-the-box for such a task.

 

Powershell script comes to play

Get-ChildItem 'D:' -Recurse | Select-Object -Property fullname | ? {$_.FullName -match '\.csv$'} | Out-File 'E:\allcsv.csv'

then import the summary file "E:\allcsv.csv" into PQ,

CNENFRNL_0-1646509909553.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

If all of the files in the different subfolders have the same structure, you can use Folder.Files, and then the transform query will help you combine them.  If there are differently structured files in each folder, I would replace Folder.Files with Folder.Contents, which will give you a view of the different folders, into which you can drill down into the individual files.

 

--Nate

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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