Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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:
Issue:
Question:
Many thanks in advance!
My current "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" = Table.FirstN(#"Sorted Rows",1),
#"Filtered Hidden Files1" = Table.SelectRows(#"Kept First Rows", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File (2)", each #"Transform File (2)"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1",{"Source.Name", "Date modified", "Transform File (2)"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File (2)", Table.ColumnNames(#"Transform File (2)"(#"Sample File (2)"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Date modified", type date}, {"Pers.No.", Int64.Type},
{"Date", type date}, {"Org. Unit", Int64.Type}, {"Full Name", type text}, {"Emp. Type.", type text}, {"User Name", type text}, {"Position", type text},
{"Start date", type date}, {"End Date", type date}, {"Project Name", type text}})
in
#"Changed Type"
My current "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" = Table.FirstN(#"Sorted Rows",1),
Navigation1 = #"Kept First Rows"{0}[Content]
in
Navigation1
Hi Dino,
First off, thanks for helping out. I really appreciate this!
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 51 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 64 | |
| 39 | |
| 33 | |
| 23 |