Sub topic 13
Refreshing in the Power BI service: when you need a gateway
This chapter assumes you can publish a report from Power BI Desktop to the Power BI service. It also assumes you have already built Excel, CSV, and SharePoint queries as covered in earlier chapters. The goal is to predict, before you publish, whether a scheduled refresh will work. If it won't, you should know what it needs.
What a refresh actually does
A report built on Excel, CSV, or SharePoint files uses Import mode. The data is copied into the semantic model (the dataset) when you click Refresh in Desktop. After publishing, the copy in the service is frozen until the service runs the model's queries again.
The service runs those queries in the Microsoft cloud, not on your PC. The cloud engine must be able to reach each source and sign in to it. That requirement decides whether you need a gateway.
An on-premises data gateway is a program you install on a machine inside your network. It lets the cloud service send a query to that machine. The machine runs the query against sources it can reach and returns the results.
The deciding question: can the cloud reach the source?
| Source in your query | Reachable from the cloud? | Gateway needed? | Typical credential |
|---|---|---|---|
| `C:\Data\Sales.xlsx` on your PC | No | Yes | Windows account that can read the file |
| `\\fileserver\reports\orders.csv` | No | Yes | Windows account that can read the share |
| SharePoint Online file (`SharePoint.Files`) | Yes | No | OAuth2 (Microsoft 365 sign-in) |
| SharePoint Online list (`SharePoint.Tables`) | Yes | No | OAuth2 (Microsoft 365 sign-in) |
| OneDrive for Business file through its SharePoint URL | Yes | No | OAuth2 |
A path starting with a drive letter or \\ points into a private network. A URL starting with https://contoso.sharepoint.com points to a public cloud endpoint.
Local files: what the gateway setup needs
A local file path in a published model fails to refresh until you complete four things.
- Install a gateway. Install it on a machine that is usually on. Use standard mode for shared reports. Personal mode is tied to one user and stops when that user's machine is off or signed out.
- Place the file where the gateway machine can read it. The gateway runs as a Windows service. By default it runs as
NT SERVICE\PBIEgwService, not as you. That account must have read access to the path. - Use a UNC path or a local path on the gateway machine. Mapped drive letters (such as
Z:\) belong to your interactive login session. The gateway service does not see them. Use\\server\share\...instead. - Map the model to the gateway. In the service, open the model's settings and find the gateway connection section. Choose the gateway and the data source entry that matches your file path.
The path in the model must match the gateway data source exactly. A trailing backslash or a different server name (fileserver versus fileserver.corp.local) makes the gateway treat them as different sources.
SharePoint Online: no gateway, but sign-in matters
SharePoint Online is reachable from the cloud, so the service connects directly. The service still needs a stored credential. This is a common source of failures.
After publishing, open the model's settings and expand Data source credentials. For a SharePoint source, choose OAuth2 and sign in with an account that can read the site. The refresh runs as that account. If the account loses access, changes its password, or is removed, the refresh fails even though the report is unchanged.
Use the site root URL in the connector, not a link to one file. These two queries from earlier chapters work in the service without a gateway:
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
SalesTablelet
Source = SharePoint.Tables("https://contoso.sharepoint.com/sites/Sales", [ApiVersion = 15]),
Tasks = Source{[Title = "Tasks"]}[Items]
in
TasksBoth queries use the same site URL. The service stores one credential per site URL, so one sign-in covers them.
Parameters in the service
If you replaced a hard-coded path with a parameter, the service can change it without republishing. This query builds its path from a text parameter named FolderPath:
let
Source = Csv.Document(File.Contents(FolderPath & "orders.csv"), [Delimiter = ",", Encoding = 65001]),
Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true])
in
PromotedIn the model settings, open Parameters and edit FolderPath. The next refresh uses the new value. This helps when a test and a production file share one report layout.
Parameter changes do not update the gateway data source for you. If FolderPath now points to a different server, you must add a matching data source to the gateway, or the refresh fails with a credentials or access error.
Privacy levels in the service
Privacy levels control whether data from one source can be sent to another source during a query. The values are Public, Organizational, and Private. When one query combines a local file with a SharePoint list, Power Query decides how to evaluate the merge. If the two sources have levels that block sharing, the refresh fails with a Formula.Firewall error.
The service uses the levels configured for each data source. For gateway sources, set the privacy level on the data source entry. For cloud sources, set it under Data source credentials in the model's settings.
Two practical rules help:
- Give related business sources the same level, usually Organizational.
- Do not turn privacy levels off in Desktop to hide the problem. Settings in Desktop do not carry over to the service, so the error comes back after publishing.
Scheduling and limits
Open the model's settings, expand Scheduled refresh, and turn it on. Choose a frequency, time zone, and times.
- Pro and Premium Per User licenses allow up to 8 scheduled refreshes per day.
- Models in Premium or Fabric capacity allow up to 48 per day.
- A scheduled refresh can be disabled automatically. This happens when it fails four times in a row, and also when nobody has used the report for two months.
- Refresh has a time limit (2 hours on shared capacity, 5 hours on Premium). Large unfiltered file folders can hit it.
Turn on refresh failure notifications and send them to a group mailbox. Without them, a disabled schedule is easy to miss until someone notices stale numbers.
Checking a refresh before users do
- After publishing, open the model's settings and read the warnings. A yellow banner often says "You can't schedule refresh because this dataset isn't configured properly." That means a missing gateway mapping or credential.
- Click Refresh now once. This runs the same path as a scheduled refresh.
- Check Refresh history. Failed rows show an error code and a message. The message names the data source that failed.
- Fix one thing at a time, then refresh again.
Common failures and their causes
| Message or symptom | Likely cause | Fix |
|---|---|---|
| "You can't schedule refresh because this dataset isn't configured properly" | Local path with no gateway mapping | Install or choose a gateway, then map the data source |
| "The gateway is offline" or "unreachable" | Gateway machine off, or service stopped | Start the gateway service, check the machine |
| "Access to the path is denied" | Gateway service account lacks file permissions | Grant read access, or run the service as a suitable account |
| "Could not find a part of the path" | Mapped drive letter, or the path differs on the gateway machine | Use a UNC path |
| "Invalid credentials" on SharePoint | OAuth2 token expired, or the signed-in account lost access | Sign in again under Data source credentials |
| `Formula.Firewall` | Mismatched privacy levels across combined sources | Align the levels |
| Refresh disabled | Four consecutive failures or two months of no use | Fix the cause, then turn the schedule back on |
Exercise
A report reads D:\Exports\orders.csv from the analyst's laptop and a SharePoint Online list named Tasks. After publishing, scheduled refresh fails for the CSV query only. Name the two things you could do to make the whole model refresh reliably, and one trade-off for each.
Show answer
Option 1: install a standard-mode gateway on an always-on machine, move the CSV to a path that machine can read (preferably a UNC share), and map the CSV data source to the gateway. Trade-off: you now maintain a gateway and the service account's file permissions, and the machine must stay on. Option 2: move the CSV to a SharePoint document library and change the query to SharePoint.Files. Then both sources use OAuth2 with no gateway. Trade-off: the file has to be uploaded or synced to SharePoint, and the refresh account needs read access to that site. The Tasks list already refreshes without a gateway, so it needs no change in either case.
Exercise
A gateway data source is set up for \\fileserver\reports\orders.csv. A colleague changes the FolderPath parameter in the service to \\fileserver.corp.local\reports\. The next refresh fails. Why, and what do you do?
Show answer
The new path doesn't match any gateway data source. The gateway treats fileserver and fileserver.corp.local as different sources. Add a gateway data source for the new path, or set the parameter back to the original value. Then map the model to the matching data source and refresh again.