Sub topic 3
Connecting to a SharePoint Online List
Assume you know Power BI Desktop, Power Query, and basic tables. You should also understand that a query is a sequence of transformations that produces a table.
Connect to a SharePoint Online list
Choose Get data > SharePoint Online List, enter the site URL, and sign in. Select the list in Navigator, then choose Transform Data to inspect it in Power Query.
let
Source = SharePoint.Tables(
"https://contoso.sharepoint.com/sites/Sales",
[ApiVersion = 15]
),
Tasks = Source{[Title = "Tasks"]}[Items],
SelectedColumns = Table.SelectColumns(
Tasks,
{"Title", "Status", "DueDate"}
)
in
SelectedColumnsUse the SharePoint list connector for structured list items. Use SharePoint Folder when the site stores Excel or CSV files.
| Source | Best choice |
|---|---|
| SharePoint list items | SharePoint Online List |
| Several files in a site folder | SharePoint Folder |
| One known workbook | SharePoint Files or a direct file connection |
Combine files with the same layout
The SharePoint Folder connector returns file metadata and binary content. Filter the folder and extension before combining files. Each workbook must have the same table or sheet structure.
let
Source = SharePoint.Files(
"https://contoso.sharepoint.com/sites/Sales",
[ApiVersion = 15]
),
Files = Table.SelectRows(
Source,
each [Extension] = ".csv"
and Text.Contains([Folder Path], "/Shared Documents/Monthly/")
),
Tables = Table.AddColumn(
Files,
"Rows",
each Table.PromoteHeaders(
Csv.Document([Content], [Delimiter = ",", Encoding = 65001])
)
),
Combined = Table.Combine(Tables[Rows])
in
CombinedReplace paths with parameters
Create a text parameter named FolderPath, then reference it instead of embedding a location. Parameters make development, testing, and deployment easier.
let
Source = Csv.Document(
File.Contents(FolderPath & "orders.csv"),
[Delimiter = ",", Encoding = 65001]
),
Orders = Table.PromoteHeaders(Source, [PromoteAllScalars = true])
in
OrdersCredentials, privacy, and refresh
Set credentials under Data source settings. Use an organizational account for SharePoint Online. Privacy levels control whether Power Query may combine data from different sources.
SharePoint Online normally refreshes in the Power BI service without a gateway. Local files require an on-premises data gateway because the service cannot reach your computer or internal network directly.
Troubleshoot refresh errors
- Access denied: Reauthenticate and verify site or list permissions.
- Item not found: Check the list title, folder path, and file name.
- Privacy error: Review privacy levels or separate incompatible source combinations.
- Gateway offline: Start the gateway service and confirm its data-source credentials.
- Schema error: Compare column names and types across files.
Exercise
Which connector should you choose for several CSV files stored in one SharePoint folder?
Show answer
Choose SharePoint Folder, filter the files, and combine their contents with a consistent transformation.