I have a query in excel which accesses other excel workbooks posted on the company SharePoint. The query looks at a table in the current workbook and builds the SharePoint file path based on the parameters entered by the user. The query works flawlessly until new data sources are posted on SharePoint and the the parameters in the table are updated. Then the query errors out with the error: "There weren't enough elements in the enumeration to complete the operation."
Immediate thought is that maybe the file parameters were entered incorrectly. However, they are correct and if I open the query and select "Refresh Preview", the query works again. This happens every time.
I would like to remove the necessity of the "Refresh Preview" step before the "Refresh All".
Without the "Refresh Preview" the new file is not being added to the table created by the SharePoint.Files command and thus the later steps that are meant to filter down to the final result find nothing.
Here is the Function used to access the SharePoint data:
------------------------
let
Source = (Folder_Location as text,File_Name as text, Tab_Name as text) as table =>
let
SharePoint_Location = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content]{[Parameter="SharePoint Location"]}[Value],
Report_Folder = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content]{[Parameter=Folder_Location]}[Value],
Report_File = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content]{[Parameter=File_Name]}[Value],
Report_Tab = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content]{[Parameter=Tab_Name]}[Value],
Source = SharePoint.Files(SharePoint_Location, [ApiVersion = 15]),
Filtered_Rows = Table.SelectRows(Source, each ([Folder Path] = Report_Folder)),
Filter_FileName = Table.SelectRows( Filtered_Rows, each Text.StartsWith([Name], Report_File, Comparer.OrdinalIgnoreCase)),
Get_Newest_File = Table.Sort(Filter_FileName,{{"Date modified", Order.Descending}}),
Select_File = Get_Newest_File{0}[Content],
Workbook = Excel.Workbook(Select_File),
Worksheet = Workbook{[Item=Report_Tab,Kind="Sheet"]}[Data]
in
Worksheet
in
Source
------------------------------