How to Connect SQL Server to Power BI

Galaxy Glossary

How do I connect SQL Server to Power BI Desktop and Service?

Use Power BI Desktop’s SQL Server connector to import or query data from an on-prem or Azure SQL Server database for interactive reporting.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why use Power BI’s SQL Server connector?

Direct connectivity removes CSV exports and keeps dashboards live. Scheduled refreshes or DirectQuery allow near-real-time views of Orders, Customers, and revenue.

How do I set up the SQL Server connector in Power BI?

Open Power BI Desktop → Get Data → SQL Server. Enter server name, optional database, and choose Import or DirectQuery. Provide credentials (Windows, Database, Microsoft Entra).Click OK.

Which authentication method should I pick?

Use Windows for on-prem AD, Database for SQL logins, or Microsoft Entra for Azure SQL. Ensure the login has at least db_datareader on the required database.

How can I filter tables before loading?

In Navigator, tick only Customers, Orders, Products, and OrderItems. Use Transform Data to apply row filters or rename columns before loading.

How do I write a custom SQL query?

From the connector window, expand Advanced options, paste your T-SQL, and pick Import/DirectQuery.Power BI uses this query as the data source.

Example T-SQL for revenue by month

SELECT DATEFROMPARTS(YEAR(order_date), MONTH(order_date), 1) AS month_start, SUM(total_amount) AS monthly_revenueFROM OrdersGROUP BY DATEFROMPARTS(YEAR(order_date), MONTH(order_date), 1)ORDER BY month_start;

How do I schedule data refresh?

Publish the report to Power BI Service → Dataset settings → Scheduled refresh. Provide a gateway if the SQL Server is on-prem.

Best practices for performance

Select only needed columns, add indexes on Orders.order_date and OrderItems.order_id, and prefer Import for static data, DirectQuery for near-real-time.

.

Why How to Connect SQL Server to Power BI is important

How to Connect SQL Server to Power BI Example Usage


-- Show top 10 products by sales in Power BI using SQL Server
SELECT TOP 10 p.id, p.name,
       SUM(oi.quantity)         AS units_sold,
       SUM(oi.quantity*p.price) AS revenue
FROM   OrderItems AS oi
JOIN   Products   AS p ON p.id = oi.product_id
GROUP  BY p.id, p.name
ORDER  BY revenue DESC;

How to Connect SQL Server to Power BI Syntax


-- Connection parameters in Power BI Desktop
Server:  <server_name>[\instance]
Database: <optional_db_name>
Authentication:
  • Windows (Integrated)
  • Database (User / Password)
  • Microsoft Entra ID (Azure)
Advanced options:
  • Command timeout (minutes)
  • Native SQL statement (custom T-SQL)

-- Example custom query pulled via Import mode
SELECT c.id, c.name, c.email,
       o.id   AS order_id,
       o.order_date,
       o.total_amount
FROM   Customers   AS c
JOIN   Orders      AS o ON o.customer_id = c.id
WHERE  o.order_date >= DATEADD(month, -12, GETDATE());

Common Mistakes

Frequently Asked Questions (FAQs)

Can I connect to multiple databases on the same server?

Yes, create separate data sources or qualify objects with the database name inside a single custom query.

Is a gateway required for Azure SQL?

No. Gateways are only needed for on-prem SQL Server. Azure SQL connections refresh natively in the Power BI Service.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.