A refresh timeout error means Power Query sent a command to a database or external data source, but the server took longer to respond than the client software was configured to wait. By default, relational database connectors in Excel enforce client-side query time limits. When an unindexed table scan, complex view, or heavy server workload exceeds this threshold, the connection terminates with an error such as “Timeout expired” or “Execution Timeout Expired.”
Quick Answer
Open the Power Query Advanced Editor and add the
CommandTimeoutparameter to your source step record, formatted as#duration(days, hours, minutes, seconds). For example, changeSql.Database("ServerName", "DBName")toSql.Database("ServerName", "DBName", [CommandTimeout = #duration(0, 0, 30, 0)])to increase the wait limit to 30 minutes.
What You Need to Know About CommandTimeout
In Power Query, data connections differentiate between two types of timeouts:
- Connection Timeout: How long Excel attempts to establish an initial handshake with the host server (typically 15 to 30 seconds). If the server cannot be reached, the issue is network routing, VPN access, or offline hardware.
- Command Timeout: How long Excel waits for the server to process a query and return records once the connection is established.
Connectors such as Sql.Database, Oracle.Database, PostgreSql.Database, and Odbc.Query support the CommandTimeout option. The default duration varies by connector and environment (often defaulting between 10 and 30 minutes, or inheriting driver defaults). If a backend operation runs longer than that limit, Power Query cuts the line to prevent an infinite hang.
How to Apply the CommandTimeout Parameter
You can define this parameter either when setting up a new connection or by editing an existing query.
Method 1: Setting the Parameter via the User Interface
When connecting to a database for the first time:
- Navigate to Data > Get Data > From Database > From SQL Server Database (or your specific database connector).
- Enter the Server and Database names.
- Click the arrow next to Advanced options to expand the hidden settings.
- Locate the field labeled Command timeout in minutes (optional).
- Enter a numeric value that accommodates your longest report extraction (for instance,
45). - Click OK.
┌────────────────────────────────────────────────────────┐
│ SQL Server Database │
├────────────────────────────────────────────────────────┤
│ Server: production-db.internal.network │
│ Database: Finance_Reporting │
│ │
│ ▼ Advanced options │
│ Command timeout in minutes (optional): [ 45 ] │
└────────────────────────────────────────────────────────┘
Method 2: Editing Existing M-Code in the Advanced Editor
If you already built transformations on top of the connection, update the M-code directly without recreating your steps:
- Open the Power Query Editor (Data > Get Data > Launch Power Query Editor).
- Select your query from the left-hand pane.
- On the Home tab, click Advanced Editor.
- Locate the initial
Source = ...step. - Insert
[CommandTimeout = #duration(0, 0, 45, 0)]into the options record.
Original Step:
Source = Sql.Database("db-cluster-01", "SalesData")
Modified Step with 45-Minute Timeout:
Source = Sql.Database("db-cluster-01", "SalesData", [CommandTimeout = #duration(0, 0, 45, 0)])
The #duration function uses four arguments:#duration(Days, Hours, Minutes, Seconds)
For a two-hour window, specify #duration(0, 2, 0, 0).
What to Do If the Query Still Times Out
If increasing the client-side CommandTimeout does not stop the timeout error, work through the following failure points.
1. Check for Server-Side Execution Limits
A client application cannot override hard server limits. If your database administrator configured SQL Server’s remote query timeout to 600 seconds, the database engine will terminate the thread after 10 minutes regardless of your Excel settings.
- The Diagnostic Check: Ask the database administrator to verify whether the query aborts with a transaction termination message or if connection pools are configured with aggressive execution caps.
- For server-side tuning and view optimization, see Solving “Query Timeout” by adjusting the CommandTimeout parameter in M-code and Handling “Timeout Expired” errors in large-scale SQL views.
2. Verify Query Folding Status
In most cases, an unexpectedly slow query in Excel is caused by a Query Folding break.
When query folding is active, Power Query translates transformations (filtering rows, sorting, grouping) into native SQL statements and executes them on the database server. If you insert a transformation that Power Query cannot fold (such as an unsupported custom text manipulation or indexing step), Excel must download the entire unfiltered table across the network and process it locally in memory.
- How to Check: Right-click the last step in your Applied Steps list.
- If View Native Query is greyed out, folding has broken.
- Inspect earlier steps to locate the exact transformation that disabled folding. Move native operations (like date filters and row selections) to the very top of your applied steps so the database engine executes the filter prior to client-side transformations.
- For troubleshooting broken folding logic, consult Troubleshooting “Query Folding” breaks: Why your SQL is running slow in Excel.
3. Confirm Asynchronous Execution Conflicts
If timeouts occur only during a full workbook refresh and not when previewing individual steps inside the Power Query Editor, queries are likely competing for connection threads in the background. See Fixing “The background refresh of ‘Query’ failed.” to configure foreground execution.