Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Basics: How to Clean and Transform Data

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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 through a process called ETL (Extract, Transform, Load), meaning you can automate the repetitive task of scrubbing messy data so that you only have to perform the cleaning steps once; thereafter, a simple refresh button updates your data based on those same rules.

What You'll Need

  • A computer with Microsoft Excel (2016 or later) or Power BI Desktop installed.
  • A data source to practice with, such as a CSV file, an Excel workbook, or a folder containing multiple files.
  • Basic familiarity with how tables and columns work in a spreadsheet.

Step-by-Step

  1. Connect to Your Data Source
    Open Excel and navigate to the Data tab on the top ribbon. In the Get & Transform Data group, click Get Data. From the dropdown menu, select your source. For beginners, From File > From Text/CSV or From File > From Excel Workbook are the best starting points. Browse to your file, select it, and click Import. Note that menu labels may differ slightly depending on your version of Excel or region.
  2. Enter the Power Query Editor
    Once you select your file, a preview window will appear showing a snapshot of your data. Do not click Load immediately, as this simply dumps the raw data into your sheet. Instead, click Transform Data. This opens the Power Query Editor, a separate window where all the cleaning magic happens.
  3. Promote Headers
    Often, Power Query doesn't automatically recognize the first row of your data as the column titles. If your headers are currently listed as "Column1", "Column2", etc., and your actual titles are in Row 1, go to the Home tab and click Use First Row as Headers. This moves your data titles to the top, making the dataset much easier to manage.
  4. Set Correct Data Types
    Every column in Power Query has a data type (indicated by a small icon to the left of the column header, such as 1.2 for decimals or ABC for text). If a date column is marked as text, you won't be able to sort it chronologically. Click the data type icon and select the correct format (e.g., Date, Whole Number, or Currency). This ensures that calculations and filters work accurately.
  5. Remove Unnecessary Columns
    Large datasets often contain "noise"—columns you don't actually need for your analysis. To clean this up, hold the Ctrl key and click the headers of the columns you want to keep. Right-click one of the selected headers and choose Remove Other Columns. This is safer than deleting columns one by one because it explicitly defines what stays in your final report.
  6. Filter Out Garbage Data
    Click the dropdown arrow in a column header to see a list of all unique values. Uncheck "null" values, blank rows, or error entries that would skew your results. For example, if you have a "Sales" column and some rows contain "N/A", unchecking "N/A" will remove those rows from the entire dataset.
  7. Split Columns
    If you have a column that combines data (like "City, State"), you can separate them. Right-click the column header, select Split Column > By Delimiter. Choose the comma as the delimiter and click OK. Power Query will automatically create two separate columns for you.
  8. Replace Values
    If your data has inconsistent naming (e.g., some rows say "USA" and others say "United States"), right-click the column and select Replace Values. Type "USA" in the Value To Find box and "United States" in the Replace With box. This standardizes your data for better grouping and pivoting.
  9. Merge or Append Queries
    If you have two different tables that share a common ID (like a Customer ID), use Merge Queries on the Home tab to join them into one wide table. If you have multiple files with the same structure (like monthly sales reports) and want to stack them on top of each other, use Append Queries.
  10. Load the Data to Excel
    Once the data looks exactly how you want it, click Close & Load in the top left corner of the Home tab. This will exit the editor and place your cleaned, transformed data into a new Excel table.

Common Mistakes

One of the most frequent mistakes beginners make is clicking Load instead of Transform Data. Loading raw data bypasses the cleaning process and forces you to do manual cleanup in the spreadsheet, which defeats the purpose of using Power Query. Another common error is ignoring data types. If you leave a numeric column as "Text," you will find that you cannot sum the values or use them in mathematical formulas once the data is loaded into Excel.

Many users also forget that Power Query is case-sensitive. If you are filtering for "Apple" but some rows say "apple," Power Query will treat them as two different items. Always use the Format > Capitalize Each Word or Uppercase tool to standardize text before filtering or grouping. Finally, avoid renaming columns too early in the process; if you rename a column and then try to use a step that refers to the original name, you may trigger an error in the Applied Steps list.

Tips

The most powerful feature for beginners to master is the Applied Steps pane on the right side of the editor. Every action you take—filtering, splitting, or changing a type—is recorded here as a step. If you make a mistake, you don't need to hit Undo; simply click the "X" next to the specific step in the list to delete it and revert the data to its previous state.

To speed up your workflow, use the Column From Examples feature. Instead of figuring out a complex formula to extract a piece of text, you can simply type what you want the result to look like in a new column, and Power Query will analyze your pattern and write the transformation logic for you. Additionally, if you are importing data from a folder, use the Combine Files option. This allows you to point Power Query to a folder; whenever you drop a new monthly CSV into that folder and hit Refresh in Excel, the new data is automatically cleaned and added to your table without you having to repeat any steps.

Troubleshooting

If your query fails after you have loaded it to Excel, the first thing to check is the Source Path. If you moved the original CSV or Excel file to a different folder, Power Query will not be able to find it. To fix this, go to Data > Queries & Connections, right-click your query, select Edit, and then click the gear icon next to the Source step in the Applied Steps pane to update the file path.

If you see an "Expression Error" stating that a column was not found, it usually means the column name in your source file has changed. For example, if the source column was "Date" and it is now "Transaction Date," the subsequent steps in your query will break. You can fix this by clicking the step immediately before the error and renaming the column in the source file to match the original, or by editing the formula bar in the Power Query Editor to reflect the new name.

If the Power Query Editor is running very slowly, try to Filter your data as early as possible in the Applied Steps list. By removing unnecessary rows and columns at the beginning of the process, you reduce the amount of data the engine has to process in the later, more complex steps. If the software freezes, restart Excel and check if there are any pending Office updates, as stability improvements are frequently released.

Frequently Asked Questions

Do I need to know how to code to use Power Query?

No. While Power Query uses a language called "M" in the background, almost every common transformation can be done using the buttons and menus in the user interface without writing a single line of code.

Can I use Power Query on a Mac?

Power Query is available for Excel on Mac, but the feature set is more limited than the Windows version. Some advanced connectors and transformation tools may not be available depending on your specific version of Office 365.

What happens if my source data changes?

As long as the column names and file location remain the same, you simply click Data > Refresh All in Excel. Power Query will re-run every recorded step on the new data and update your table automatically.

Is Power Query the same as a Pivot Table?

No. A Pivot Table is used to summarize and analyze data that is already clean. Power Query is used to clean and prepare the data before it ever reaches the Pivot Table.

Can I import data from a website?

Yes. By selecting Get Data > From Other Sources > From Web, you can enter a URL. Power Query will analyze the page and allow you to extract data from any HTML tables it finds on that website.