Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Gateway for Cross-Database SQL Query

Is it possible to utilize a cross-database SQL Query in Power BI's Online Service? For example, I have a query that I am importing (NOT using DirectQuery) into a Power BI Desktop File that follows this structure:

 

Select a.*, b.*

FROM Server1.Database1.Table1 a

INNER JOIN Server1.Database2.Table2 b on b.id = a.id

 

It is merging data from two different databases within the same SQL Server. When importing the query into Power BI Desktop I have to explicitly list the Server and Database as Server1 and Database1, respectively. The refresh works fine in the Desktop version but when I upload to the Online Service and attempt to set-up a refresh schedule I receive an error because the Gateway connection pointing to Database1 cannot access Database2 under the current security context. I receive the "Unable to connect to the data source undefined" error (Class: 14, Number: 916 - DataSource Error).

Therefore, I was wondering if it is possible to create a gateway connection for a SQL Query that accesses multiple databases within the same server? Or is there a Gateway setting that would allow this to happen? I would assume there are multiple case scenarios of Users importing cross-database queries into Power BI's online service. Has anyone else had this issue/come up with a solution?

I do not want to create two data source connections pointing to each table individually and merging in the BI User Interface as they are both very large fact tables (Also connects to multiple dimensional tables). Would I require a SQL View that accesses both tables or would the issue still persist?

 

Any help is appreciated!

3 REPLIES 3
GilbertQ
Super User
Super User

Hi there

What I have done is to use all SQL queries with one datasource in Power BI Desktop.

If I need to do a cross-database query I would do the following:

DataSource Database = MyDB1.dbo.tb_TableName

Query to another database would be:
MyDB2.dbo.tb_OtherTableName

That works well for me.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

I am looking for a way to merge the queries before loading into Power BI (Please see last paragraph of question). Otherwise the analysis would take ages given the vast quantity of records in both respective databases/tables being accessed.

You could achieve it with a view, which would then present itself as coming from a single data source?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.