diff --git a/samples/TripPin/9-TestConnection/Table.GenerateByPage.pqm b/samples/TripPin/9-TestConnection/Table.GenerateByPage.pqm index a753257..14a6b72 100644 --- a/samples/TripPin/9-TestConnection/Table.GenerateByPage.pqm +++ b/samples/TripPin/9-TestConnection/Table.GenerateByPage.pqm @@ -1,23 +1,23 @@ -(getNextPage as function) as table => - let +( + getNextPage as function, + optional tableType as type +) as table => +let listOfPages = List.Generate( - () => getNextPage(null), // get the first page of data - (lastPage) => lastPage <> null, // stop when the function returns null - (lastPage) => getNextPage(lastPage) // pass the previous page to the next function call - ), - // concatenate the pages together - tableOfPages = Table.FromList(listOfPages, Splitter.SplitByNothing(), {"Column1"}), - firstRow = tableOfPages{0}? - in - // if we didn't get back any pages of data, return an empty table - // otherwise set the table type based on the columns of the first page - if (firstRow = null) then - Table.FromRows({}) - // check for empty first table - else if (Table.IsEmpty(firstRow[Column1])) then - firstRow[Column1] - else - Value.ReplaceType( - Table.ExpandTableColumn(tableOfPages, "Column1", Table.ColumnNames(firstRow[Column1])), - Value.Type(firstRow[Column1]) - ) + () => getNextPage(null), + (lastPage) => lastPage <> null, + (lastPage) => getNextPage(lastPage) + ), + filteredListOfPages = List.Select(listOfPages, each not Table.IsEmpty(_)), + tableOfPages = Table.FromList(filteredListOfPages, Splitter.SplitByNothing(), {"Column1"}), + firstRow = tableOfPages{0}?, + appliedType = + if tableType <> null then tableType + else if firstRow <> null then Value.Type(firstRow[Column1]) + else type table[], + columns = Record.FieldNames(Type.RecordFields(Type.TableRow(appliedType))) +in + Value.ReplaceType( + Table.ExpandTableColumn(tableOfPages, "Column1", columns), + appliedType + )