Power Query is a data transformation and data preparation engine that allows you to import data from various sources, clean it, reshape it, and load it into a destination like Excel or Power BI. Its primary feature is the "ETL" process: Extract (connecting to data), Transform (cleaning and modifying), and Load (sending the data to a table or model). Unlike traditional formulas, Power Query records every change you make as a sequential step, allowing you to refresh the data later without repeating the manual work.
What You'll Need
- A computer with Microsoft Excel (2016 or later, or Office 365) or Power BI Desktop installed.
- A data source to connect to, such as a CSV file, an Excel workbook, a SQL database, or a web URL.
- Appropriate permissions or login credentials to access the external data sources you intend to import.
Step-by-Step
- Connect to Your Data Source: Open Excel and go to the Data tab. In the Get & Transform Data group, click on Get Data. You will see a list of options including File, Database, and Other Sources. Select the source that matches your data (for example, File > From Text/CSV). Note that menu labels may vary slightly depending on your version of Excel or region.
- Import the Data: Once you select the source, a navigator window will appear. Browse the files or tables available in that source. Select the specific table or sheet you want to work with. Instead of clicking Load, click Transform Data. This opens the Power Query Editor window, which is where the actual feature set of the tool is utilized.
- Clean the Data Columns: Look at your data headers. If the first row of your data is not being recognized as the header, go to the Home tab and select Use First Row as Headers. To remove unnecessary information, right-click a column header and select Remove, or hold Ctrl to select multiple columns before removing them.
- Change Data Types: Power Query assigns a data type to every column (e.g., Text, Whole Number, Date, Currency). Check the icon to the left of the column header. If a date column is listed as text, click the icon and select Date. This is critical because calculations and date-based filtering will not work correctly if the data type is wrong.
- Filter and Sort Rows: Click the drop-down arrow on a column header to filter out specific values, such as removing nulls or filtering for a specific year. You can also sort the data in ascending or descending order. These actions are recorded as steps in the Applied Steps pane on the right side of the screen.
- Split Columns: If you have a column containing combined data (like "City, State"), right-click the column header and select Split Column. Choose Split by Delimiter and select the comma. Power Query will automatically split the data into two separate columns.
- Pivot and Unpivot Data: If your data is in a "cross-tab" format (where dates are columns), select those columns, right-click, and choose Unpivot Columns. This transforms the data into a long, narrow format that is much easier to analyze with Pivot Tables.
- Merge and Append Queries: To combine data from two different tables, use Merge Queries (similar to a VLOOKUP or JOIN) to add columns from one table to another based on a matching ID. To stack two tables on top of each other (provided they have the same columns), use Append Queries.
- Create Custom Columns: Go to the Add Column tab and select Custom Column. Here, you can write a simple formula using the Power Query M language to create new data based on existing columns (e.g., [Price] * [Quantity]).
- Load the Final Result: Once the data is cleaned, go to the Home tab and click Close & Load. This will send the transformed data back into an Excel table or the Power BI data model.
Common Mistakes
One of the most frequent errors is failing to check data types before performing calculations. If you try to sum a column that Power Query has categorized as "Text," the operation will fail or return an error. Always verify that numbers are formatted as decimals or whole numbers and dates are formatted as dates.
Another common mistake is deleting the source file or changing the file path after the query has been set up. Power Query remembers exactly where the file was located on your hard drive or server. If you move the file to a different folder, the query will break because it can no longer find the source path. To fix this, you must go to Data Source Settings and update the path.
Users often forget that Power Query is case-sensitive. If you are filtering for "New York" but the data contains "new york," the filter will exclude the lowercase version. To avoid this, use the Transform tab to change the entire column to Uppercase or Lowercase before applying filters.
Finally, some users try to perform manual edits in the Excel table after loading the data from Power Query. Any manual changes made to the resulting table will be overwritten the next time you click Refresh, as Power Query re-runs all the recorded steps from the original source.
Tips
Utilize the Applied Steps pane to your advantage. If you make a mistake, you do not need to undo every action; simply click the X next to the specific step in the Applied Steps list to remove that transformation. You can also click on previous steps to see how the data looked at that specific point in the process.
When dealing with very large datasets, use the "Remove Columns" feature as early as possible in your step sequence. By removing unnecessary data early, you reduce the amount of memory Power Query needs to process the remaining steps, which significantly speeds up the refresh time.
Explore the "Column From Examples" feature. Instead of writing a complex formula, you can simply type a few examples of what you want the output to look like in a new column, and Power Query will attempt to figure out the pattern and write the M code for you automatically.
Group your queries. If you are importing ten different files from the same folder, create a "Parameter" for the folder path. This way, if the folder moves, you only have to change the path in one place rather than updating ten individual queries.
Troubleshooting
If you encounter a "Data Format Error" during a refresh, it usually means the source data has changed in a way that contradicts your steps. For example, if you told Power Query a column was "Whole Number" but a new row contains a text string like "N/A," the query will error. To fix this, go back into the Power Query Editor, find the step where the error occurs, and either clean the source data or change the data type to "Any" or "Text."
If the "Close & Load" button is grayed out or the application freezes, check the size of your data source. If you are attempting to load millions of rows into an Excel sheet, you may exceed Excel's row limit (1,048,576 rows). In this case, instead of loading to a table, select "Only Create Connection" and check the box "Add this data to the Data Model." This allows you to analyze the data using a Pivot Table without actually loading the raw rows into the spreadsheet.
When a query fails to refresh due to a "Privacy Level" error, it is usually because you are combining data from two different sources (like a local CSV and a web API). Go to File > Options and settings > Query Options > Privacy and select "Ignore the Privacy Levels" to allow the data to merge, provided you trust both sources.
If the Power Query Editor window does not open after clicking Transform Data, ensure that your Office installation is fully updated. In some cases, conflicting add-ins can prevent the editor from launching. Try disabling non-essential Excel add-ins via File > Options > Add-ins.
Frequently Asked Questions
Is Power Query the same as Power Pivot?
No. Power Query is used for getting and cleaning data (ETL), while Power Pivot is used for data modeling, creating relationships between tables, and writing complex DAX measures for analysis.
Can Power Query connect to a website?
Yes. By selecting Get Data > From Web, you can enter a URL. Power Query will analyze the page and attempt to identify any HTML tables that can be extracted as structured data.
Do I need to know how to code to use Power Query?
No. Most transformations are done using the ribbon interface and right-click menus. While Power Query uses a language called "M," the tool writes the code for you as you click the buttons.
Can I use Power Query on a Mac?
Power Query is available for Excel for Mac, but it has fewer connectors than the Windows version. Some advanced features, like certain database connections, may be limited.
How do I update the data in my table?
You do not need to re-import the data. Simply go to the Data tab and click Refresh All. Power Query will re-run all the recorded steps on the current source file and update your table automatically.
Can I combine multiple files from one folder?
Yes. Use Get Data > From File > From Folder. Power Query will list all files in that directory, and you can use the "Combine Files" feature to stack them into a single master table.