Forum Discussion
Deevo_
2 years agoResolver I
How to add error redundancy to current Power Query code if data source is empty
Hi All, I receive an error "Error: There weren't enough elements in the enumeration to complete the operation.". I want to add error redundancy to my query below, but unsure how. Scenario: I ...
Anonymous
2 years agoNot applicable
Hi Deevo_ ,
To implement error redundancy in your Power Query for situations where a data file might be missing, you can use the 'try...otherwise...' construct to handle errors gracefully. This construct allows you to attempt an operation and specify an action to take if an error occurs.
"data loading query"
let
Source = Folder.Files("\\ReportData\FY_Data\"),
#"Filtered Rows1" = Table.SelectRows(Source, each [Folder Path] = "\\ReportData\FY_Data\"),
#"Filtered Rows" = Table.SelectRows(#"Filtered Rows1", each Text.Contains([Name], "Data - 1")),
#"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Date modified", Order.Descending}}),
#"Kept First Rows" = try Table.FirstN(#"Sorted Rows",1) otherwise null,
// Include the rest of your steps here, but make sure to check for null before proceeding
....
//
in
#"Changed Type"
"help query"
let
Source = Folder.Files("\\ReportData\FY_Data\"),
#"Filtered Rows1" = Table.SelectRows(Source, each [Folder Path] = "\\ReportData\FY_Data\"),
#"Filtered Rows" = Table.SelectRows(#"Filtered Rows1", each Text.Contains([Name], "Data - 1")),
#"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Date modified", Order.Descending}}),
#"Kept First Rows" = try Table.FirstN(#"Sorted Rows",1) otherwise null,
Navigation1 = if #"Kept First Rows" <> null then #"Kept First Rows"{0}[Content] else null
in
Navigation1
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.