Sub topic 3
When a dataset needs an on-premises data gateway
This chapter assumes you can build a report in Power BI Desktop with Power Query, know what a dataset (semantic model) and a workspace are, and understand basic Windows networking such as services, firewalls, and outbound ports. It builds on the previous chapters about storage modes and scheduled refresh.
The core question
The Power BI service runs in the cloud. When it has to read data, it must be able to reach the data source. A cloud service such as Azure SQL Database or a public web API accepts connections from the internet, so the service can connect directly. A SQL Server on your corporate network, a file share, or a database in a private virtual network does not. The service cannot open a connection into those networks.
An on-premises data gateway solves this. It is software you install on a machine inside the network. It makes an outbound connection to the service and relays queries and results. This chapter helps you decide, for a given dataset, whether you need one.
The decision depends on two things
Two facts about a dataset decide the matter:
- Where each data source lives, and whether the service can reach it directly.
- How the dataset uses the source: import refresh, DirectQuery, or live connection.
The storage mode tells you when the service contacts the source. Import contacts it during each refresh. DirectQuery contacts it every time a user opens or interacts with a report. A live connection to Analysis Services does the same through the model. The location tells you whether that contact can succeed without a gateway.
Data sources that need a gateway
A gateway is needed when the service cannot reach the source on its own. Typical cases:
- SQL Server, Oracle, or other databases on a corporate network or on a virtual machine without a public endpoint.
- SQL Server Analysis Services (SSAS) or other on-premises models used with a live connection.
- Excel, CSV, or other files on a local drive or network file share.
- Sources inside an Azure virtual network that are not publicly reachable.
- ODBC or OLE DB sources that depend on a driver installed on a local machine.
Data sources that do not need a gateway
- Cloud services with a public endpoint that the Power BI service can reach, such as Azure SQL Database, Azure Synapse, Dataverse, or SharePoint Online.
- Files stored in OneDrive for Business or SharePoint Online, when the query uses the cloud URL rather than a local path.
- Public web pages and public REST APIs.
A cloud source can still need a gateway if network rules block the service. For example, an Azure SQL Database with a firewall that denies Power BI service addresses cannot be refreshed directly. Reachability matters more than the product name.
Gateway requirements by storage mode
| Storage mode | When the service reads the source | Source is on-premises | Source is a reachable cloud source |
|---|---|---|---|
| Import | During scheduled or on-demand refresh | Gateway needed for refresh | No gateway |
| DirectQuery | On every report interaction | Gateway needed for every query | No gateway |
| Live connection to SSAS | On every report interaction | Gateway needed | Not applicable for Azure Analysis Services |
| Composite (Import and DirectQuery) | Both, per table | Gateway needed for each on-premises source | No gateway |
Notice the difference in consequences. With Import, a missing or offline gateway means the refresh fails, but reports keep showing the last imported data. With DirectQuery or a live connection, an offline gateway means visuals fail to load, because there is no cached copy to fall back on.
Mixed sources
Many datasets combine sources, for example a SQL Server table joined to a SharePoint Online list. If at least one source needs a gateway, the dataset needs a gateway for refresh. The gateway handles the on-premises source. The service reaches the cloud source directly.
Each gateway-served source must be defined as a data source on the gateway. A dataset can be mapped to one gateway, so all on-premises sources in that dataset must be served by the same gateway cluster.
Here is a Power Query query for a SQL Server source. The server and database names appear in the dataset and must match the gateway data source exactly, because the service uses them to map the dataset to that gateway data source.
let
Source = Sql.Database("sql01.contoso.local", "Sales"),
Orders = Source{[Schema = "dbo", Item = "Orders"]}[Data]
in
OrdersIf the gateway data source were defined as SQL01 instead of sql01.contoso.local, the service would not recognize it as the same source. This is a common reason a gateway is installed but the dataset still shows "You can't schedule refresh because this dataset gets data from sources that currently don't support refresh" or does not offer the gateway in its settings.
Dynamic and unsupported patterns
Some query patterns stop the service from working out which sources a dataset uses until the query runs. The service then cannot map the dataset to a gateway data source ahead of time.
- A data source built from a parameter or a computed string can work if the service can evaluate it statically. A fully dynamic source, such as one where the URL is assembled from the results of another query, often fails the check.
- For web sources, the service wants a base URL it can recognize. Use the
RelativePathandQueryoptions ofWeb.Contentsto keep the base fixed.
If you see a message that the dataset has a dynamic data source and cannot be refreshed, look at the failing query in Power Query and make the source location a fixed literal or a parameter.
Checking what a dataset needs
You can work out the answer for a dataset in a few steps.
- In Power BI Desktop, open Transform data, then Data source settings. List every source.
- For each source, ask whether the Power BI service could connect to it from the public internet. If not, it needs a gateway.
- For each table, note whether it is Import or DirectQuery.
- In the Power BI service, open the dataset's settings. If a gateway is required and none is configured, the Gateway and cloud connections section tells you that you must set one up, and scheduled refresh cannot be saved.
The service helps with this check. When a dataset has an on-premises source and no matching gateway, the settings page shows a message that a gateway is required, and the refresh schedule cannot be turned on.
Personal mode and the same question
The need for a gateway does not depend on which gateway type you choose. Both standard mode and personal mode answer the same question: how does the service reach this source? The next chapter compares the two modes. For now, remember that personal mode supports only import refresh, so a dataset using DirectQuery or a live connection to an on-premises source needs a standard-mode gateway.
Common mistakes
- Assuming that a gateway is needed because a source is "SQL Server". An Azure SQL Database is SQL Server technology, but it is reachable by the service.
- Assuming that no gateway is needed because the report works in Desktop. Desktop runs on your machine inside the network. The service does not.
- Using a local file path such as
C:\Data\sales.xlsx. The service cannot read your drive. Either use a gateway with a file source it can reach, or move the file to SharePoint Online or OneDrive for Business and use its URL. - Defining the gateway data source with a different server string than the one in the query.
- Forgetting that a dataset with two on-premises sources on different gateways cannot be refreshed. Put both on the same gateway cluster.
Summary of the decision
Ask where the source is, not what it is. If the service cannot connect to it over the public internet, install a gateway. Choose standard mode if you use DirectQuery or live connections, or if several people share the dataset.
Exercise
A dataset has two tables. One is imported from an Azure SQL Database that allows Power BI service access. The other uses DirectQuery against a SQL Server on the corporate network. Does it need a gateway, and when is the gateway used?
Show answer
Yes. The on-premises SQL Server needs a standard-mode gateway, and it is used on every report interaction that queries the DirectQuery table. The imported Azure SQL table needs no gateway, because the service reaches it directly during refresh.
Exercise
A report loads data from \\fileserver\finance\budget.xlsx. It refreshes in Desktop, but scheduled refresh in the service reports that a gateway is required. What are two ways to resolve this?
Show answer
Install a gateway on a machine that can reach the file share and add a gateway data source for that path, or move the file to SharePoint Online or OneDrive for Business and change the query to use its URL, which removes the need for a gateway.