Forum Discussion
Connect to Excel file in SharePoint library using Service Principal (SPN)
- 11 months ago
Short answer: service principals don’t work with Web data sources in the Service. Your Excel is being accessed with the Web connector, so the “Service principal” option fails.
What to do
In Power BI Desktop, change the query to use SharePoint Folder (v2) (or “SharePoint”/“SharePoint Online”) – connect with the site URL only, then filter to the file (Name/FolderPath).
Publish. In the Service → Dataset settings → Data source credentials, pick OAuth2 → Service principal and enter Tenant ID / App ID / Secret.
Permissions: use Sites.Selected and grant the app access to that site (Graph or PnP):
Grant-PnPAzureADAppSitePermission -AppId <appId> -Site <siteUrl> -Permissions Read
(Files.Read.All alone won’t grant site access when using Sites.Selected.)If you must keep the Web connector, use a gateway or user OAuth—SPN is not supported there.
Also clear any old credentials in Desktop/Service before switching.
- 11 months ago
Hi sb991986,
Thank you for reaching out to the Microsoft Fabric Community Forum and providing all the details. Also, thanks to VahidDM, for his inputs on this thread. It makes the picture very clear. I can see why this is puzzling, since your service principal works with SharePoint lists but not with Excel files in a document library.
This behaviour is expected. Here is why: The SharePoint List connector in Power BI supports service principal authentication. However, when connecting to an Excel file in a SharePoint library, Power BI uses the Web/SharePoint Folder connectors, which currently have limited support for service principal (app-only) authentication. That is why you see the 400 invalid credentials error when trying to update credentials in the Power BI Service.Grant site/document library access: If you are using Sites.Selected, the service principal needs to be explicitly granted access to the site/document library so it can read the actual file content. https://learn.microsoft.com/en-in/graph/api/site-post-permissions?view=graph-rest-1.0&tabs=http
Use Graph API instead of the Web connector: Instead of connecting directly to the Excel file via Web, use Microsoft Graph API in Power Query (Web.Contents) to fetch the file content. This pattern is fully supported with service principals.
1. https://learn.microsoft.com/en-us/graph/use-the-api
2. https://learn.microsoft.com/en-us/graph/Your setup is correct, but the connector limitation is the reason lists work while Excel files in libraries don’t. The supported path is to grant the service principal content access and switch to a Graph API-based connection for the Excel file.
Hope this clears it up. Let us know if you have any doubts regarding this. We will be happy to help.
Thank you for using the Microsoft Fabric Community Forum.
Short answer: service principals don’t work with Web data sources in the Service. Your Excel is being accessed with the Web connector, so the “Service principal” option fails.
What to do
In Power BI Desktop, change the query to use SharePoint Folder (v2) (or “SharePoint”/“SharePoint Online”) – connect with the site URL only, then filter to the file (Name/FolderPath).
Publish. In the Service → Dataset settings → Data source credentials, pick OAuth2 → Service principal and enter Tenant ID / App ID / Secret.
Permissions: use Sites.Selected and grant the app access to that site (Graph or PnP):
Grant-PnPAzureADAppSitePermission -AppId <appId> -Site <siteUrl> -Permissions Read
(Files.Read.All alone won’t grant site access when using Sites.Selected.)
If you must keep the Web connector, use a gateway or user OAuth—SPN is not supported there.
Also clear any old credentials in Desktop/Service before switching.