Microsoft Power Query is a data transformation and preparation engine that allows you to import data from various sources, clean it, reshape it, and load it into a destination like an Excel spreadsheet or a Power BI report. It achieves this by recording a series of transformation steps—such as removing empty rows, splitting columns, or merging tables—which can be refreshed automatically whenever the source data changes, eliminating the need for manual repetitive cleaning or complex formulas.

What You'll Need

  • A computer running Windows or macOS.
  • Microsoft Excel (2016 or later) or Power BI Desktop.
  • Access to a data source (this could be a CSV file, an Excel workbook, a SQL database, a web page, or a folder containing multiple files).
  • Appropriate permissions or credentials to access the data source if it is hosted on a server or cloud service.

Step-by-Step

  1. Launch Power Query: Open Microsoft Excel. Navigate to the Data tab on the top ribbon. In the Get & Transform Data group, click on Get Data. Depending on your version, you may see options like Get Data > From File > From Workbook or From Text/CSV. Note that menu labels may differ slightly based on your version of Office or region.
  2. Connect to Your Data Source: Select the source of your data. For example, if you are importing a CSV file, select From Text/CSV and browse your local folders to select the file. Once selected, click Import. Power Query will open a preview window showing how it interprets the data (e.g., identifying delimiters like commas or tabs).
  3. Enter the Power Query Editor: In the preview window, you will see three options: Load, Transform Data, and Cancel. To clean your data, always click Transform Data. This opens the Power Query Editor, a separate window where all the cleaning and shaping takes place without affecting the original source file.
  4. Clean the Data (The Transformation Phase): Use the ribbon tools to shape your data. Common actions include:
    • Removing Columns: Right-click a column header you do not need and select Remove.
    • Filtering Rows: Click the dropdown arrow in a column header and uncheck values you want to exclude (e.g., removing "Null" or "Blank" entries).
    • Changing Data Types: Click the icon to the left of the column header (e.g., ABC or 123) and select the correct type, such as Date, Currency, or Text. This ensures calculations work correctly later.
    • Splitting Columns: If a column contains both a first and last name, right-click the header, select Split Column > By Delimiter, and choose Space.
  5. Manage Applied Steps: Look at the Applied Steps pane on the right side of the editor. Every action you take is recorded here as a step. If you make a mistake, click the X icon next to the specific step to undo it. You can also rename steps by right-clicking them to make the process easier for others to understand.
  6. Merge or Append Queries: If you have data in two different tables, use the Home tab. Use Merge Queries to join tables based on a common column (similar to a VLOOKUP or SQL Join). Use Append Queries to stack one table on top of another (similar to a UNION in SQL), provided they have the same column structure.
  7. Load the Data: Once the data is cleaned, click Close & Load in the top left corner of the Home tab. You can choose Close & Load to bring the data directly into an Excel table, or Close & Load To... to choose whether the data should be loaded as a PivotTable report or only added to the Data Model for Power Pivot.
  8. Refresh the Data: When the original source file is updated with new information, you do not need to repeat these steps. Go to the Data tab in Excel and click Refresh All. Power Query will re-run every recorded step in the Applied Steps pane and update your table instantly.

Common Mistakes

One of the most frequent errors is failing to set the correct data types. If a column is left as "Any" or set to "Text" when it should be "Decimal Number," any subsequent mathematical operations or PivotTable summaries will fail or produce incorrect results. Always verify your data types before loading.

Another common mistake is relying on hard-coded cell references or specific file paths that change. If you move your source file to a different folder, Power Query will throw an error because it can no longer find the path. To avoid this, try to keep your source files in a consistent directory or use a Power Query parameter for the file path.

Users often forget that Power Query is case-sensitive. If you filter a column for "Completed" but the data contains "completed" (lowercase), those rows will be excluded. To fix this, use the Transform tab > Format > Capitalize Each Word or Lowercase to standardize the text before applying filters.

Over-complicating the transformation process is also a risk. Adding dozens of small steps can slow down the refresh time. Whenever possible, combine transformations or perform the most restrictive filters first to reduce the amount of data Power Query has to process in later steps.

Tips

Use the "Column From Examples" feature for complex transformations. Instead of searching for a specific tool, go to the Add Column tab and select Column From Examples. You can type a few examples of what you want the final result to look like, and Power Query will automatically write the logic (the M code) to achieve that pattern for the rest of the rows.

When importing multiple files from a single folder, use the "Combine Files" option. This allows you to treat a whole folder as a single data source. As long as the files have the same structure, any new file dropped into that folder will be automatically included the next time you hit Refresh.

Learn the basics of the Formula Bar. While the ribbon handles most tasks, the formula bar shows the M language code. If you are comfortable with basic logic, you can tweak the code directly in the bar to make your transformations more dynamic or precise.

Utilize the "Unpivot Columns" feature to fix "cross-tabbed" data. If your data has months as column headers (January, February, etc.), it is difficult to analyze. By selecting those columns and choosing Transform > Unpivot Columns, you turn those headers into a single "Month" column and their values into a "Value" column, making the data "long" and ready for PivotTables.

Troubleshooting

If you encounter a "Data Source Error" or a "Could not find file" message, the first step is to check the file path. Go to Data > Get Data > Data Source Settings. Select the source and click Change Source to browse for the file in its new location. Ensure the file name has not been changed, as Power Query requires an exact match.

If the refresh process is extremely slow, check your Applied Steps for "Sort" or "Merge" operations that occur early in the sequence. Sorting large datasets is resource-intensive. Try to filter out unnecessary rows and columns first to reduce the dataset size before performing complex joins or sorts.

When you see "Error" written in individual cells after loading, it usually means a data type mismatch occurred during the refresh. For example, a cell might contain the word "N/A" in a column that Power Query expects to be a Number. To fix this, go back into the Power Query Editor, find the column, and use the Transform tab > Replace Values to change "N/A" to 0 or null before the "Changed Type" step.

If the Power Query Editor window fails to open or crashes, check for pending Microsoft Office updates. Ensure your system has enough available RAM, as Power Query loads a preview of the data into memory. If you are working with millions of rows, consider loading the data directly to the Data Model (Close & Load To... > Only Create Connection + Add this data to the Data Model) rather than loading it into a worksheet.

Frequently Asked Questions

Is Power Query the same as Power Pivot?

No. Power Query is used for extracting, cleaning, and transforming data (ETL). Power Pivot is used for data modeling, creating complex relationships between tables, and writing DAX measures for advanced calculations.

Can I use Power Query on a Mac?

Yes, but functionality is more limited than on Windows. While newer versions of Excel for Mac support importing data and basic Power Query transformations, some advanced connectors and features may not be available.

Does Power Query change the original source file?

No. Power Query is read-only regarding the source. It reads the data, applies transformations in its own memory, and outputs the result to a new location. Your original CSV or Excel file remains untouched.

What is the "M" language?

M is the formula language used behind the scenes in Power Query. Every button you click in the editor generates a line of M code. While you can use the editor visually, you can also write M code manually for advanced logic.

How many sources can I connect to at once?

You can connect to as many sources as your system memory allows. You can import data from a SQL server, a web page, and an Excel file simultaneously and then merge them into a single table using the Merge Queries feature.

Can I automate the refresh schedule?

In Excel, you can set the data to refresh every X minutes or refresh on open via the Connection Properties. For fully automated cloud scheduling, you would need to use Power BI Service or a Power Automate flow.