Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I want to know how to recursively process files in subfolders of onedrive. This is needed for consolidating the data from all the excel files in given folder and all subfolders underneath.. I already have PowerQuery written to go to a specific folder and process all the files in that. However, it needs to happen recursively for all the sub-folders and sub-sub-folder in that. Any guidance please?
it is just a guess, but try if this is a good starting point:
let
dirall=(path)=>
let
Source = Folder.Contents(path),
dir=List.Accumulate(Table.ToRows(Source[[Content],[Name]]),{},(s,c)=>if Value.Is(c{0}, type table) then s&@dirall(path &"\"& c{1}) else s&{c{1}} )
in dir
in
dirall
this function recursively goes through all the folders and subfolders of a directory and supplies only the name of the files.
but only you know what else to do with these files
here a version that add some action to the files.
let
dirall=(path)=>
let
Source = Folder.Contents(path),
dir=List.Accumulate(Table.ToRows(Source[[Content],[Name]]),{},(s,c)=>if Value.Is(c{0}, type table) then s&@dirall(path &"\"& c{1}) else s&{[name=c{1},len=Text.Length(Text.BeforeDelimiter(c{1},".")) ]} )
in dir
in
dirall
for each files name the last number is the number file in the subfolder.
f212 for example is the second file in the filder f21 which is the first subfolder of folder f2 wich is the second subfolder of folder "test"
may be this could be more usefull to your goal
let
dirall=(path)=>
let
Source = Folder.Contents(path),
dir=List.Accumulate(Table.ToRows(Source[[Content],[Name]]),{},(s,c)=>if Value.Is(c{0}, type table) then s&@dirall(path &"\"& c{1}) else s&{path & "\"& c{1}} )
in
dir
in
dirall
having all the files with complete path you can apply your function (I suppose)
#####
in the following form it is probably easier to understand
let
dirall = (path) => List.Accumulate(
Table.ToRecords(Folder.Contents(path)),
{},
(s, c) =>
if Value.Is(c[Content], type table) then
s & @dirall(path & "\" & c[Name])
else
s & {path & "\" & c[Name]}
)
in
dirall
Do this using the SharePoint connector @mumbaicharaja
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI Reporting@mumbaicharaja , refer if these can help
https://powerbi.microsoft.com/en-us/blog/combining-excel-files-hosted-on-a-sharepoint-folder/
User | Count |
---|---|
11 | |
7 | |
5 | |
5 | |
4 |
User | Count |
---|---|
15 | |
14 | |
8 | |
6 | |
6 |