Forum Discussion
SharePoint list query alternative or optimization
- 5 years ago
hjaf FYI that I finally made a video to describe this approach, and am adding it here for others that may find this post. It also gets the count of items and makes the right number of API calls.
Get SharePoint List Data with Power BI ... Fast - YouTube
Also, a reminder to mark one of these as the solution.
Regards,
Pat
mahoneypat you are awesome!
I have tried replying and asking for guidance only to have my post marked as spam. But I eventually came up with a solution. Do you concur with this? Quote or correct it, then I'll mark mark your reply as a solution so that other people may get the whole picture 🙂
The query i ended up at that seems to be working(replaced RED values):
- Column1 values is created with: List.Generate(() => 0, each _ < 120000, each _ + 5000)
- SPItems: Json.Document(Web.Contents("https://TennantShortName.sharepoint.com/sites/SiteName/_api/web/lists(guid'ListGUID')/items?$skipToken=Paged=TRUE%26p_ID="&Text.From([Column1])&"&$top=5000", [Headers=[Accept="application/json"]])))
Complete commented query:
let
Source = List.Generate(() => 0, each _ < 120000, each _ + 5000), // Generate a list that increments 5000 up to max value 120 000
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), // Convert the list into a table
#"Added Custom" = Table.AddColumn(#"Converted to Table", "SPItems", each Json.Document(Web.Contents("https://<TennantShortName>.sharepoint.com/sites/<SiteName>/_api/web/lists(guid'<ListGUID>')/items?$skipToken=Paged=TRUE%26p_ID="&Text.From([Column1])&"&$top=5000", [Headers=[Accept="application/json"]]))), //custom column that does the actual query to sharepoint
//Note: replace <TennantShortName>, <SiteName> and <ListGUID>
//Instead of using list guid, you can use list names with GetByTitle(): "https://<TennantShortName>.sharepoint.com/sites/<SiteName>/_api/Web/Lists/GetByTitle('<List Title>')/items?$skipToken=Paged=TRUE%26p_ID="&Text.From([Column1])&"&$top=5000"
#"Expanded SPItems" = Table.ExpandRecordColumn(#"Added Custom", "SPItems", {"odata.metadata", "odata.nextLink", "value"}, {"odata.metadata", "odata.nextLink", "value"}), //expand the results
#"Removed Duplicates1" = Table.Distinct(#"Expanded SPItems", {"odata.nextLink"}), // Remove the duplicated nextLink items to get unique items
#"Expanded value" = Table.ExpandListColumn(#"Removed Duplicates1", "value"), // Expand the results from queries into new rows
#"Expanded value1" = Table.ExpandRecordColumn(#"Expanded value", "value", {"Id", "Title"}), // Expand wanted columns in the sharepoint list
#"Removed Columns" = Table.RemoveColumns(#"Expanded value1",{"Column1", "odata.metadata", "odata.nextLink"}), // Remove columns from the initial query.
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Id", Int64.Type}, {"Title", type text}}) // Type setting
in
#"Changed Type"
I really like this method, it is super fast and super easy to configure. However, I have found that whilst using this method, it doesn't pick up all the fields. I have tried expanding all the rows and columns, selecting all values but if simple does not pick up the one field I need. I really don't want to use a v2 connector as it is slow and terrible.
Any help would be appreciated.
- CmdrKeene4 years agoHelper IV
I can try to poke around and see if I can find a solution. What type of field is missing?
I will mention that person fields did not come in in a format that was great for me, so in my power query I also pulled in the user information table and then used the user ID to relate to it.
- ElliotK4 years agoHelper I
The field in questrion is called Name, which appears to be a text field. This field is required as it links back to a SharePoint attachment so I wish to use the values contained to connect to the corresponding attachment via its URL.
The field in question IS exposed if I use a v2 connector, but I did not want to go down this route and would much rather use your solution.
- CmdrKeene4 years agoHelper IV
That's really odd, for me all the text fields just show up. Is it maybe a lookup field on the front-end of SharePoint? Or you're sure it's either "single line of text" or "multiple lines of text" on the list itself?