Sub topic 7
Choosing a SharePoint connection option
This chapter assumes you can open Get Data in Power BI Desktop, read Power Query Editor applied steps, and load an Excel table or CSV file. It covers how to pick the right connector for SharePoint Online data before you build any queries.
Three ways to reach SharePoint data
SharePoint Online holds two kinds of data: files in document libraries, and items in lists. Power BI has a connector for each, plus a general web route to a single file.
| Option | Connector | Returns | Best for |
|---|---|---|---|
| SharePoint Folder | `SharePoint.Files` or `SharePoint.Contents` | A table of file metadata and binary content | Excel and CSV files, especially many files with the same layout |
| SharePoint Online List | `SharePoint.Tables` | The items of a list, as a table | Data entered through SharePoint list forms |
| Web (file URL) | `Web.Contents` | One file's contents | A single file that you reach by direct URL |
How to decide
Ask what the data is stored as. A list is a structured table that SharePoint manages. A file is a document that you must open and parse yourself.
- If the data lives in a list, use the SharePoint Online List connector.
- If the data lives in files and there are many of them, use SharePoint Folder.
- If it is a single file, either SharePoint Folder or a file URL works. SharePoint Folder is easier to parameterize and to keep consistent with the other file sources in your report.
The site URL is the root, not the folder
Both SharePoint connectors ask for a site URL. Enter the site address, such as https://contoso.sharepoint.com/sites/Sales. Do not paste the address of a library, folder, or file from your browser's address bar. Power Query then lists everything it finds on the site, and you filter down to what you need.
SharePoint.Files returns every file in every library on the site. On a large site this is slow, so filter early on Folder Path and Name. SharePoint.Contents returns a folder tree that you navigate one level at a time, which can be quicker when you know the path.
What each option looks like in M
The SharePoint Folder option lists files, then you pick one by name and folder path:
let
Source = SharePoint.Files("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
FileContent = Source{[Name = "Sales.xlsx", #"Folder Path" = "https://contoso.sharepoint.com/sites/Sales/Shared Documents/"]}[Content],
Workbook = Excel.Workbook(FileContent, true, true),
SalesTable = Workbook{[Item = "Sales", Kind = "Table"]}[Data]
in
SalesTableThe list option returns items directly, with no file parsing:
let
Source = SharePoint.Tables("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
Tasks = Source{[Title = "Tasks"]}[Items]
in
TasksThe later chapters on files and lists walk through these queries step by step.
Authentication
SharePoint Online sign-in normally uses an organizational account. Power BI stores credentials per data source, and you set them at the site URL level. When the first query asks you to sign in, choose the organizational account option and select the broadest URL level that covers your queries, so one sign-in applies to every query against that site.
Common mistakes
- Pasting a folder or file URL into the site URL box instead of the site root.
- Using the Folder connector for list data, then wondering why no items appear.
- Leaving
SharePoint.Filesunfiltered on a large site, which makes refresh slow.
Exercise
Your team keeps a Tasks list on a SharePoint site and monthly CSV exports in a document library on the same site. Which connectors do you use for each, and what site URL do you enter?
Show answer
Use the SharePoint Online List connector for the Tasks list and the SharePoint Folder connector for the CSV files. Enter the site root, for example https://contoso.sharepoint.com/sites/Sales, in both cases, not a library or folder address.