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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply

M query using folder.contents questions

I have almost 20K files in the folder and I only need to load some of files based on naming. In my M query, I am using folder.contents first and then filter out the files after.

 

But the challenge is folder.contents always load all 20K files even I only need few files. The performance is unacceptable. I do not own the files and could not change the files and folder. How can I filter out the files in folder.contents? or is there any function I can use?

 

Thanks,

W

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Spread out the files into different folders

View solution in original post

Anonymous
Not applicable

let
    Source = Table.FromColumns({Lines.FromBinary(File.Contents("D:\folder\index.txt"), null, null, 936)}),
    #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Column1], "wanted")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "path", each "D:\folder\" & [Column1]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Content", each File.Contents([path]))
in
    #"Added Custom1"

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

or you can generate a file index file, load it, filter, load the required files after filtering

Hi GSun,

 

Thanks for your quick turnaround. 

 

I am not the owner of the files and not the option to spread the files. 

For your second suggestions, how can I make it in M query to only load the files I need?

 

Thanks,

W

Anonymous
Not applicable

let
    Source = Table.FromColumns({Lines.FromBinary(File.Contents("D:\folder\index.txt"), null, null, 936)}),
    #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Column1], "wanted")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "path", each "D:\folder\" & [Column1]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Content", each File.Contents([path]))
in
    #"Added Custom1"

Hi Gsun,

 

This is smart. It worked.

 

Thans for your help!

W

Anonymous
Not applicable

Spread out the files into different folders

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors