Sub topic 9
Connecting to a SharePoint Online list
This chapter assumes you can open Power BI Desktop and the Power Query Editor, and that you know how applied steps work. It also assumes you have read the earlier chapters on choosing a SharePoint connection option and on reading files from a SharePoint site.
A SharePoint Online list stores rows and columns on a SharePoint site, much like a table. Teams use lists for task trackers, request logs, and inventories. A list is not a file. There is no workbook to open and no CSV to parse. Power BI reads the list through a SharePoint list connector, so you connect to the site, and Power Query then offers the lists on that site as tables.
When to use the list connector
Choose the list connector when the data lives in a SharePoint list. If the data is in an Excel workbook or CSV file stored in a document library, use the file-based options from the previous chapter.
| Question | List connector | Files (SharePoint Folder or Files) |
|---|---|---|
| What is the source? | A list on a SharePoint site | A workbook or CSV in a document library |
| What does Power Query return? | One table per list, with list columns | A file listing, then file contents you parse yourself |
| Who edits the data? | Users in the SharePoint list form or grid | Users in Excel or an export process |
| Typical cleanup | Expand record columns, set types | Promote headers, choose sheets or tables |
The next diagram shows the decision.
Connect from Power BI Desktop
- Select Get data, then More, and search for SharePoint Online List.
- Select Connect.
- Enter the site URL, for example
https://contoso.sharepoint.com/sites/Sales. - If the dialog offers an implementation choice, keep the default unless you have a reason to change it. Select OK.
- If prompted, choose Organizational account and sign in with the account that has access to the site.
- In the Navigator, tick the list you want, such as Tasks, then select Transform Data to clean the table before loading.
The URL must be the address of the site, not of a list or a list view. A URL such as https://contoso.sharepoint.com/sites/Sales/Lists/Tasks/AllItems.aspx fails or returns the wrong object. Trim it back to the part ending with the site name. The connector then lists every list and library on that site.
What the generated query looks like
When you pick a list in the Navigator, Power Query writes M code like this. You can see it by opening Advanced Editor.
let
Source = SharePoint.Tables("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
Tasks = Source{[Title = "Tasks"]}[Items]
in
TasksThis code has two steps:
SharePoint.Tablesconnects to the site and returns a table with one row for each list. The optionApiVersion = 15selects the SharePoint 2013 and later API, which SharePoint Online uses.Source{[Title = "Tasks"]}[Items]picks the row whoseTitleisTasks, then reads itsItemscolumn. That column holds the list rows as a nested table.
The Desktop dialog may also add options to the call, depending on your version. Treat the generated code as the source of truth, and edit it only when you understand the option.
Selecting the list by its Title makes the step depend on the list name. If someone renames the list in SharePoint, this step fails with an error that the key matched no rows. Fix the name in the step, or use a parameter as described in the parameters chapter.
Clean the list columns
A SharePoint list has more columns than the view you normally see. The connector often returns system columns, such as an ID, creation and modification fields, and content-type information. It also returns columns you never display. Keep only what the report needs.
let
Source = SharePoint.Tables("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
Tasks = Source{[Title = "Tasks"]}[Items],
Selected = Table.SelectColumns(Tasks, {"Title", "Status", "DueDate"}, MissingField.UseNull),
Typed = Table.TransformColumnTypes(Selected, {{"DueDate", type date}})
in
TypedMissingField.UseNull makes a missing column return null instead of raising an error. This keeps the refresh running if the column is removed from the list, but it also hides the problem. Your report will show blanks until someone notices. Use the default behavior, which raises an error, if you would rather learn about the change at the next refresh.
Replace the column names with the ones in your list. A list that has no DueDate column makes the type step fail.
Column types you will meet
List columns do not all arrive as plain text or numbers. Check the type icon in each column header.
| List column type | What you may see in Power Query | Typical fix |
|---|---|---|
| Single line of text | Text | Usually none |
| Number, Currency | Number | Confirm the type |
| Date and Time | Date/time | Change to Date if you only need the day |
| Choice | Text | Usually none |
| Choice allowing multiple values | List or text, depending on the connector | Expand to rows, or combine into text |
| Person or Group | Record | Expand the record and keep the field you need |
| Lookup | Record | Expand the record and keep the field you need |
| Yes/No | Logical | Confirm the type |
A column that holds records shows the word Record in each cell and an expand icon in the header. Select the icon, then tick only the fields you need. The field names differ by column and connector implementation, so look at the preview instead of guessing them. Clear the Use original column name as prefix box if you want short names.
Expanding a multi-value column can multiply rows. A task with three assigned people becomes three rows, and a sum over a numeric column then counts the task three times. Decide whether you need one row per person or one row per task before you expand.
Authentication and privacy levels
The SharePoint list connector uses Organizational account authentication. The account you sign in with needs at least read access to the list. If a list has item-level permissions, you only receive the items that account can read. The refresh in the Power BI service uses the credentials stored for the dataset, so a report built with one person's access can show different data than another person's would.
You can manage saved credentials under File > Options and settings > Data source settings. Select the site URL, then Edit Permissions, and set the privacy level. The usual setting for company SharePoint data is Organizational. Combining sources with incompatible privacy levels, such as a list and a CSV file marked Private, can trigger a formula firewall error. The credentials chapter covers this in detail.
Refresh in the Power BI service
A SharePoint Online list is a cloud source, so the Power BI service reaches it directly. You do not need an on-premises data gateway for a dataset that only uses SharePoint Online lists. After publishing, open the dataset settings, expand Data source credentials, and sign in with an organizational account. Then configure a scheduled refresh.
Refresh fails in these common cases:
- The stored credentials have expired or belong to someone who left the organization.
- The account no longer has permission to the site or list.
- The list was renamed, so the
Titlelookup returns no row. - A column used in a step was deleted or renamed.
Local files are different. A workbook on C:\Data needs a gateway, and a list does not. If one report mixes both, the local part still needs a gateway.
Checking your work
After loading, compare the row count in Power BI with the count shown in the SharePoint list. If you have fewer rows, check item-level permissions and any filter step you added. If you have more rows, look for an expanded multi-value column.
Exercise
Your query uses Source{[Title = "Tasks"]}[Items]. A colleague renames the list to "Project Tasks" in SharePoint. What happens at the next refresh, and how do you fix it?
Show answer
The step fails because no row in the list of lists has the Title "Tasks". Edit the step to use the new name, "Project Tasks", or store the name in a parameter so that you only change it in one place.
Exercise
A Person column called AssignedTo shows the word Record in every cell. What do you do, and what risk comes with expanding a column that allows multiple people?
Show answer
Use the expand icon in the column header and select only the fields you need, such as the person's display name. If the column allows several people, expanding creates one row per person, so totals over other columns can be counted more than once.
Exercise
Does a scheduled refresh for a dataset that reads only a SharePoint Online list need an on-premises data gateway? What does it need instead?
Show answer
No. SharePoint Online is a cloud source. The dataset needs valid organizational-account credentials in its data source settings, and that account needs permission to read the list.