How To Run A Query In Excel | Pull Data Without Mistakes

Excel runs queries through Power Query, so you can pull, clean, and refresh data from files, tables, folders, and databases in minutes.

If you’re trying to learn how to run a query in Excel, the cleanest path is built right into the Data tab. In current desktop versions, that path is Power Query, which Microsoft also labels as Get & Transform. It lets you bring data in, trim what you don’t need, fix column types, and refresh the result later without rebuilding the whole sheet.

That last part is what makes queries worth using. A manual copy-paste job works once. A query keeps working. When the source file changes, you can refresh and pull in the new rows with the same steps already saved.

What a query does in Excel

A query is a saved set of instructions for getting data from a source and shaping it before it lands in your workbook. The source can be a CSV file, another workbook, a folder full of files, a web feed, or a database. Excel stores the steps, so you don’t need to repeat the cleanup work each time.

That means a query can do jobs such as:

  • pull only the sheet or table you need
  • remove blank rows and extra columns
  • split dates, names, or codes into separate fields
  • filter out old records
  • merge two tables by a shared ID
  • refresh the result when the source updates

Microsoft’s Power Query in Excel page lays out the same core idea: connect, shape, then load the result into a worksheet, chart, or report.

Before you start the query

Excel gets far less fussy when the source data is tidy. You don’t need perfect data, but you do want a few basics in place before you click Get Data.

Set up the source the right way

Use one header row. Make sure each column holds one kind of value. Don’t mix dates and text in the same field if you can avoid it. In source workbooks, turning the range into a table helps because Excel can spot it faster and keep the structure steady when rows grow.

Know where the output should land

You can load a query into a worksheet table, the Data Model, or only keep the connection. Most people should start with a worksheet table. It’s visible, easy to check, and simple to refresh.

How to run a query in Excel with Power Query

Here’s the straight path for a file-based query in Excel for Microsoft 365, Excel 2024, and recent desktop releases.

  1. Open Excel and go to the Data tab.
  2. Choose Get Data.
  3. Pick your source, such as From File > From Workbook or From Text/CSV.
  4. Select the file and wait for the preview window.
  5. Choose the sheet, table, or data object you want.
  6. Click Transform Data if you need to clean or filter it, or Load if it’s ready as is.
  7. In the Power Query Editor, apply your cleanup steps.
  8. Click Close & Load to send the result back to Excel.

Microsoft walks through the same menu flow on its Create, load, or edit a query in Excel page. If you only need a simple import, that’s enough. If the data is messy, spend a minute in the editor before loading it.

What to do inside the editor

The editor is where the real work happens. Each action becomes a saved step in the right-hand pane. You can delete a step, move back, or add another one without touching the source file.

Start with these common edits:

  • set each column to the right data type
  • remove columns you won’t use
  • filter out blanks, test rows, or old entries
  • trim spaces from text fields
  • rename headers so the sheet is easy to read

If your dates sort strangely or numbers refuse to total, the data type is often the culprit. Fix that early. It saves a lot of head-scratching later.

Step What to do Why it helps
Pick the source Choose the right file, folder, table, or database Prevents building steps on the wrong data
Preview first Check headers, blank rows, and field names Catches layout issues before load
Set data types Mark columns as text, number, date, or currency Stops sort, filter, and math errors
Remove extra columns Keep only the fields you plan to use Makes the sheet cleaner and refreshes lighter
Filter bad rows Drop blanks, totals rows, and old records Keeps summaries accurate
Rename columns Use short, plain headers Makes formulas and pivots easier to read
Close and load Send the result to a worksheet table Creates a reusable output in the workbook
Refresh later Run the saved steps again on new data Turns a one-off job into a repeatable process

When to use Load and when to use Transform Data

If the source is already clean, click Load and move on. If the file has merged headers, odd date formats, stray spaces, subtotal rows, or columns you don’t need, choose Transform Data first. That tiny pause up front often saves ten minutes of repair work after the data lands in the sheet.

A simple rule works well:

  • Load for clean tables with ready-to-use headers
  • Transform Data for anything you’d otherwise fix by hand

Refreshing a query after the source changes

Once the query is in your workbook, you don’t run the whole build again. You refresh it. Right-click the output table and choose Refresh, or go to the Data tab and use Refresh All. Microsoft also lists the refresh shortcut and connection settings on its refresh an external data connection page.

If nothing changed after refresh, check three things:

  • the source file path is still the same
  • new rows are inside the source table or the source sheet area the query reads
  • you didn’t filter the new records out in an earlier step

This is where queries beat manual imports by a mile. You build once, then refresh as often as needed.

Common places people get stuck

Most query problems come from small setup issues, not from Excel doing anything wild. If your query fails, don’t rip it up and start over. Check the saved steps one by one and watch where the preview breaks.

Problem Likely cause Fix
Dates sort out of order Date column loaded as text Change the data type to Date in the editor
New rows do not appear Source range is fixed or rows sit outside the table Turn the source into a table, then refresh
Numbers will not sum Currency or quantity column is text Set the column to Whole Number, Decimal, or Currency
Headers look wrong Extra top rows were imported Use Use First Row As Headers after removing junk rows
Refresh throws an error Source file moved or renamed Edit the source step and point to the new file
Too many blank rows Source file includes separators or notes Filter blanks out before loading

Using Excel queries for repeat work

Queries shine when the same job comes back every week or every month. Sales exports, bank downloads, order logs, stock lists, payroll extracts, lead sheets, and survey results all fit this pattern. The source changes. The cleanup rules don’t.

A solid repeat setup often looks like this:

  • save incoming files in one folder
  • keep the same column names when possible
  • build one query that pulls the data
  • build a second query only if you need a summary table
  • refresh both when new files arrive

If your workbook feeds charts or pivot tables, point them at the query output table. Then a refresh updates the whole chain with less manual work and fewer broken formulas.

If you still see Microsoft Query in Excel

Some older setups still show Microsoft Query. It can pull data from external sources, and it still works for some legacy connections. Still, Power Query is the path most Excel users should start with today because it handles cleanup steps in a clearer way and stores them right in the workbook.

So, when someone asks how to run a query in Excel, the practical answer for current versions is this: use the Data tab, get the source, shape it in Power Query, then load and refresh it when the source changes.

References & Sources