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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
GothicBelle
Regular Visitor

Needing error handling for empty folder source

I have a queue folder with many subfolders for different queue data that I download Excel files every day. Each subfolder has a query made for it, and my end result is an append of all the final tables from those queries.

My issue is some days there just isn't any queue files that gets downloaded for some of the subfolders-they are empty. So I get the error: 

 

Expression.Error: There wasn't enough elements in the enumeration to complete the operation.

Details:

   [Table]

This error shows up in the Sample File of whatever folder is empty that day.

Here's my original code:

let

   Source= Folder.Files ("S:\My Folder\Queue\Subfolders"),

   Navigation1 = Source {0}[Content]

in

   Navigation1

 

This error is happening in the Sample File for any query that the folder is empty. If there's no files there I'd like the query to either skip that empty folder or make an empty 'place holder table'

I have the feeling I should use the try..otherwise expression but where- the Sample File or in each of the tables since they also have a Source  code line??

6 REPLIES 6
Omid_Motamedise
Super User
Super User

Use this one

 

let

   Source= Folder.Files ("S:\My Folder\Queue\Subfolders"),

   Navigation1 = try Source {0}[Content] otherwise null

in

   Navigation1
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

You cannot append null to a table. Needs to be an empty table. 

 

lbendlin_0-1727791316977.png

 

lbendlin_1-1727791338568.png

 

Table:

= #table({"Column1","Column2"},{{"Q","A"}})

 

Table2:

= #table({"Column1","Column2"},{})

 

AlienSx
Super User
Super User

Source{0}?[Content]? // gives you null
lbendlin
Super User
Super User

let

   Source= Folder.Files ("S:\My Folder\Queue\Subfolders"),

   Navigation1 = if Table.CountRows(Source)>0 then Source{0}[Content] else <fake empty table with a [Content] column that you prepared before>

in

   Navigation1

This sort of worked but now my Transform Parameter is bugging out because dummies me said they were Excel files and they are CSV files.

Please provide sample data that fully covers your issue.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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