Excel Power Query and SQL: How They Work Together

How-to basics · Updated November 21, 2026

Excel Power Query can connect to a SQL database, retrieve selected data, and reshape it before loading it into a worksheet or the Data Model. In Microsoft 365 for Windows, start at Data > Get Data > From Database > From SQL Server Database; you can use Power Query’s interface for most transformations, or enter a SQL statement when you need the database to do specific work.

What Excel Power Query and SQL Each Do

SQL is a language for working with relational databases. A SQL Server database, for example, can hold many tables containing business records. SQL statements can select rows and columns, join tables, group records, and calculate summaries. Excel Power Query is Excel’s data connection and transformation tool: it connects to sources, records cleaning steps, and loads the resulting data into Excel.

They are complementary rather than competing tools. SQL can filter or combine data in the database, while Power Query can guide you through importing and shaping it for a workbook. A user can build a query by selecting columns and filtering rows in Power Query without writing SQL. Behind the scenes, Power Query stores its own transformation instructions in the M language. That is distinct from SQL, although Power Query can sometimes translate its steps into SQL for a database to run.

For example, a sales database might contain millions of order lines. You could use Power Query to connect to a SQL Server table, keep only the columns needed for a report, filter the data to the current year, and load the result as an Excel table. The source remains in the database; the workbook receives the result of the query.

Connect to SQL Server from Excel

These steps apply to Excel for Microsoft 365 on Windows. You need network access to the server and permission to connect to the relevant database. The server administrator or database team can provide the server name and confirm which authentication method your organization uses.

  1. Open the workbook and select Data > Get Data > From Database > From SQL Server Database.
  2. Enter the SQL Server name. Enter a database name if you know it; otherwise, you may be able to select one after connecting. Use the server and database details supplied by your organization.
  3. To provide a SQL statement at connection time, expand Advanced options and enter it in the SQL statement box. Leave this blank if you want to choose tables and shape them through the interface.
  4. Select OK. If prompted, choose an available authentication method and sign in. The choices depend on how the server is configured and your organization’s policies.
  5. In Navigator, select a table or view, or choose Transform Data to open the Power Query Editor and inspect or adjust the result before loading it.
  6. In the editor, choose Home > Close & Load, or use the Close & Load arrow to choose a destination such as a worksheet table or the Data Model.

The Navigator preview helps you confirm that you chose the intended object. A database may contain similarly named tables, views, and schemas, so check the object name and sample columns before loading. If Excel cannot connect, verify the server name, network or VPN access, database permission, and authentication details before changing query steps.

Choose Between the Interface and a SQL Statement

The Power Query Editor is a practical choice when you want a repeatable sequence of visible steps, such as removing columns, changing data types, filtering dates, or splitting a text field. Select a column and use the ribbon or its filter menu; Power Query adds a step to the query. The Applied Steps list lets you review, reorder in some cases, or remove those operations. This approach is accessible to people who do not know SQL and makes many routine changes easy to inspect.

A SQL statement is useful when the database should apply a specific filter or join before returning data, or when a database view does not already provide the required result. For instance, a simplified SQL Server query might be:

SELECT OrderDate, CustomerID, TotalAmount FROM dbo.Orders WHERE OrderDate >= '2026-01-01';

This requests three columns from the Orders table and filters for dates on or after January 1, 2026. The statement is illustrative: a real database may use different table and column names, and a date boundary should match the report’s requirements. SQL dialects vary between database products, so syntax valid for SQL Server may need changes for another source.

Typing SQL is not automatically faster or safer than using the editor. A query that returns unnecessary columns or too many rows can waste time and resources. If a company maintains database views for reporting, using an approved view may be clearer and easier to support than embedding a long custom statement in a workbook.

Query Folding: Why Some Steps Run in the Database

Query folding is Power Query’s ability to translate compatible transformation steps into operations the source database can perform. If you filter a SQL Server table by a date and keep only a few columns, Power Query may send an equivalent request to SQL Server. The database can then return a smaller result instead of sending every record to Excel for local processing.

Folding matters most with large tables and shared databases. Returning fewer rows and columns can reduce transfer time and memory use. Whether a step folds depends on the connector, the source, the operation, and earlier steps. Some transformations cannot be translated, and a step that does not fold may cause later work to happen in Power Query instead. A custom SQL statement can also affect which later operations the connector is able to fold.

To investigate, right-click a step in the Power Query Editor and look for View Native Query. If the option is available, it can show the source query Power Query is generating at that point. It may be unavailable for reasons that do not by themselves prove the query is incorrect or slow. For a performance issue, check the amount of data returned, the source database’s performance, and whether a simpler filter or database view can meet the need.

Load, Refresh, and Share the Results

Power Query does not make a worksheet a live window onto the database. After the data is loaded, the workbook contains a result that can be refreshed. In Excel for Windows, use Data > Refresh All to refresh workbook connections, or right-click a loaded query table and choose Refresh. The data changes in the workbook when the refresh completes successfully; until then, the displayed result may be out of date.

Excel provides different destinations for a query. Loading to a worksheet table is convenient when people need to inspect or use the rows directly. Loading to the Data Model can be useful for building PivotTables and working with related tables without placing every row on a sheet. Choosing Only Create Connection avoids placing the result in a worksheet, though it can still be used by other queries or workbook features depending on how it is configured.

Refresh behavior depends on access to the source. Someone opening a shared workbook may need their own database permissions and suitable credentials; having the workbook does not automatically grant access to the server. Refresh options can be configured in the query’s connection properties, but automatic refresh is not a substitute for checking that the source is available and the latest refresh succeeded. Excel for the web and Excel for Mac can differ from Windows in connector availability and refresh capabilities, so confirm support in the version and environment where the workbook will be used.

How to Choose the Right Approach

Use the approach that fits the scale of the data, the skills of the workbook’s owners, and the rules for the database. A small, straightforward import may be easiest to build entirely in Power Query. A complex join over large tables may be better handled by a maintained database view or a carefully written SQL query, especially if the database team can review and support it.

  • Choose the Power Query interface for discoverable, repeatable cleanup steps and straightforward filters.
  • Use SQL when database-side selection, joins, or aggregations are needed and you can maintain valid SQL for that source.
  • Ask about an existing view or approved reporting dataset when the database is managed by another team.
  • Keep the result narrow: retrieve only the rows and columns the workbook actually needs.
  • Consider who will refresh the workbook, what permissions they need, and how changes to the source schema will be handled.

There is no universal row limit that makes one method right and the other wrong. Worksheet capacity, available memory, query complexity, database performance, and refresh needs all matter. A large result may be more appropriate for the Data Model or for a report built in a different tool, while a modest extract may work well as a worksheet table.

Common Connection and Refresh Problems

A failed connection often points to access rather than a problem with Power Query steps. A server name may be mistyped, the database may be unavailable outside the office network, or a firewall or VPN may block the connection. An authentication prompt can also appear if stored credentials are expired or were saved for a different account. Follow your organization’s process for updating credentials rather than sharing passwords in the workbook.

Another common issue is a query that worked until the source changed. Renamed or removed columns, altered data types, and changes to a database view can break later transformation steps. Review the first step that shows an error and compare its expected columns with the current source. If only some records fail to convert to a number or date, inspect the source values and the locale assumptions used for conversion.

Slow refreshes may come from retrieving too much data, expensive transformations, a busy database, or a slow network. Start by limiting the rows and columns as early as possible, then check whether folding is available. Do not assume that repeatedly refreshing will fix a permissions error or a database outage. Record the error message and, when appropriate, ask the database administrator to check server-side logs or access rights.

Security and Good Data Practices

A workbook connection can reveal the server name, database name, query logic, and sometimes sensitive business context, even when it does not contain a password. Treat the workbook as a managed data asset. Store and share it using approved locations, and avoid sending extracts containing personal or confidential information to people who are not authorized to see them.

Use the least privilege needed: the account used for reporting should generally have permission to read the required data, not modify production records. Do not put passwords directly into SQL text or workbook cells. If your organization requires a gateway, managed identity, or a particular credential process, follow its instructions. Also consider whether the query’s filters protect sensitive rows: a filter in a workbook is not a replacement for database access controls, because someone with broader database access may change the query.

For shared or business-critical reports, document the source, owner, refresh expectations, and what to do when a refresh fails. A workbook that silently displays last month’s data can be misleading. A visible refresh date or a clear note about the reporting period helps readers distinguish a current extract from a stale one.

Frequently Asked Questions

Do I need to know SQL to use Power Query with a database?
No. You can connect to a table or view and apply many common transformations in the Power Query Editor. SQL knowledge helps when you need custom database-side logic, but it is not required for ordinary imports and cleanup.

Can Excel run a SQL query directly?
Yes. With the SQL Server connector in Excel for Windows, you can expand Advanced options in the connection dialog and enter a SQL statement. The statement must be valid for the connected database, and you still need permission to read the referenced objects.

Is Power Query the same thing as SQL?
No. Power Query is Excel’s connection and transformation tool, and its transformation language is M. SQL is a language used by relational databases. Power Query can translate some steps into database operations, but the two languages are not interchangeable.

Does Power Query update Excel automatically when the database changes?
Not simply because the database changes. The workbook must refresh its query, manually or through configured refresh behavior, and the source must be reachable with valid credentials. Check the refresh status and reporting period before relying on the displayed data.

Can I connect to SQL Server in Excel for Mac or Excel for the web?
Connector and refresh support can differ by platform and release. The steps above describe Microsoft 365 for Windows. Check the Get Data options and Microsoft’s current support information for your specific Mac or web version before designing a workbook that depends on SQL Server refresh there.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.