If you're manually exporting CSV files from your database and importing them into Excel every day, there's a much better way. Excel's Power Query lets you connect directly to your database, run a SQL query, and load the results into a structured table — one that refreshes with a single click.

This tutorial works with SQL Server, MySQL, PostgreSQL, and SQLite. No coding experience required beyond basic SQL.

What You'll Need

💡 Always use a read-only database user for Excel connections. Never connect with admin credentials. Ask your IT team to create a reporting user with SELECT-only permissions.

Step 1 — Install the Database Driver (MySQL/PostgreSQL only)

SQL Server and Access connect natively. For MySQL or PostgreSQL, download the free ODBC driver first:

Install the driver, then restart Excel. SQL Server users can skip this step.

1

Open Power Query

In Excel, go to Data tab → Get Data → From Database → choose your database type (SQL Server, MySQL, etc.)

2

Enter Connection Details

Server name or IP address, database name, and your credentials. For SQL Server on your local machine, try "localhost" as the server name.

3

Write Your SQL Query

In the Advanced Options section, paste your SQL query. Example: SELECT SKU, ItemName, QtyOnHand, ReorderPoint FROM Inventory WHERE QtyOnHand < ReorderPoint ORDER BY QtyOnHand ASC

4

Preview and Load

Power Query shows a preview of your results. Click "Load" to load the data into Excel as a table, or "Transform Data" to clean it up first.

5

Set Up Auto-Refresh

Right-click the table → Table → External Data Properties → check "Refresh data when opening the file". Now every time you open Excel, it pulls fresh data automatically.

Sample SQL Queries for Operations Reports

Daily Inventory Snapshot

SELECT SKU, ItemName, Category, QtyOnHand, ReorderPoint, CASE WHEN QtyOnHand = 0 THEN 'Out of Stock' WHEN QtyOnHand < ReorderPoint THEN 'Low Stock' ELSE 'OK' END AS Status FROM Inventory ORDER BY Status, QtyOnHand ASC

Orders Shipped Today

SELECT OrderID, CustomerName, SKU, Qty, ShipDate, Carrier FROM Orders WHERE ShipDate = CAST(GETDATE() AS DATE) ORDER BY ShipDate DESC

Low Stock Items with Supplier Info

SELECT i.SKU, i.ItemName, i.QtyOnHand, i.ReorderPoint, s.SupplierName, s.LeadTimeDays, s.Phone FROM Inventory i JOIN Suppliers s ON i.SupplierID = s.SupplierID WHERE i.QtyOnHand < i.ReorderPoint ORDER BY i.QtyOnHand ASC

How to Schedule Auto-Refresh

For a report that refreshes on a schedule (not just when you open it), you have two options:

🗄️ Get the SQL Report Template — Free

Pre-built Power Query connections. Just plug in your database credentials.

⬇ Download Free Template

Common Mistakes to Avoid

⚠️ Using admin credentials: Never connect Excel to your database with an admin account. Always use a read-only reporting user.
⚠️ Slow queries: If your report takes too long to refresh, add a WHERE clause to limit the data. Pull only what you need — not entire tables.
⚠️ Sharing the file: If you share the Excel file, others will be prompted for database credentials. Consider exporting a static copy for sharing.

Frequently Asked Questions

Does this work with cloud databases?
Yes — AWS RDS, Azure SQL, and Google Cloud SQL all work with Power Query. You'll need the server address, port, and credentials from your cloud provider. Make sure your IP is whitelisted in the database firewall settings.
What if I don't know SQL?
You can load entire tables without writing any SQL. In Step 3, just choose the table from the navigator instead of entering a custom query. You can then filter and transform the data using Power Query's visual interface.
Will this work with our ERP system?
Usually yes. Most ERP systems (SAP, NetSuite, Fishbowl, Odoo) have an underlying SQL database. You'll need your IT team to provide read-only credentials to the reporting database.

Related Articles