Power Query Use Cases: Real Ways to Clean and Combine Data
In this article
Power Query is a data transformation tool in Excel and Power BI that lets you clean, combine, and reshape data from multiple sources without writing code. It automates repetitive data prep tasks so you can focus on analysis. You need Excel 2016 or later (with Power Query built-in) or Power BI Desktop, both free for personal use. No add-ins or external tools are required.
What You'll Need
- Microsoft Excel 2016 or later (including Microsoft 365)
- Or Power BI Desktop (free download from Microsoft)
- A data source: Excel file, CSV, database, web page, or folder with multiple files
- Basic familiarity with spreadsheets or tables
Step-by-Step
- Open Excel or Power BI Desktop and go to the Data tab. Click Get Data, then choose your source (e.g., From Text/CSV, From Folder, From Excel).
- Select your file or folder. If selecting a folder with multiple files (like monthly sales reports), check the box to combine files automatically — this creates a unified query.
- Power Query Editor opens. Review the preview. If the first row contains column headers, click Use First Row as Headers. If not, right-click the first row and select Promote to Headers.
- Remove unwanted columns: right-click any column header and select Remove. Do this for columns you don’t need, like internal IDs or duplicate fields.
- Fix data types: click the icon under each column header (e.g., ABC, 123, or a clock) and select the correct type (Text, Whole Number, Date, etc.). Incorrect types cause errors in later steps.
- Clean text: select a text column, go to the Transform tab, and use Trim to remove extra spaces, or Replace Values to fix inconsistencies like "N/A" to blank or "USA" to "United States".
- Split columns: if a column has combined data (like "John Doe, Sales"), select the column, click Split Column by Delimiter, choose comma, and select "Each occurrence" to split into two columns.
- Filter rows: click the filter arrow in a column header, uncheck "(blank)" or specific values you want to exclude (e.g., "Cancelled" orders).
- Merge queries: if you have two tables (e.g., Sales and Customers), go to Home > Merge Queries, select the first table, then the second. Match the key column (like CustomerID), choose Inner Join, and click OK.
- Expand merged columns: after merging, click the expand icon (two arrows) in the new column header. Select only the columns you need from the second table (e.g., Customer Name, Region).
- Apply changes: click Close & Load to send the cleaned data back to Excel as a table, or Close & Load To… to load into Power BI or a Data Model.
- Refresh data: if the source file updates (e.g., new monthly CSV), right-click the table in Excel and select Refresh, or click Refresh All. Power Query re-runs all steps automatically.
Common Mistakes
- Not checking data types before transforming — text that looks like numbers can’t be summed or sorted correctly.
- Skipping the "Use First Row as Headers" step, leading to column names like "Column1", "Column2" and broken formulas.
- Combining files from different formats (e.g., one CSV, one Excel) in the same folder — Power Query may fail to match structure.
- Trying to merge tables without a unique key column — if CustomerID appears twice in one table, results will duplicate or error.
- Editing data directly in Excel after loading, then expecting Power Query to pick up changes — edits must be made in the source file, then refreshed.
- Leaving blank rows or mixed data in source files — Power Query treats blank rows as data and may misalign columns.
Tips
- Always keep your source data unchanged — Power Query works on copies, so never overwrite original files.
- Use the Applied Steps pane on the right to review or delete steps. If you make a mistake, click the X next to a step to undo it.
- If combining files, name them consistently (e.g., Sales_Jan2024.csv, Sales_Feb2024.csv) so Power Query can detect and match them.
- Use the "Advanced Editor" (View tab) to review M code if you’re comfortable with it — this helps when you need to tweak complex logic.
- Save queries as templates: after cleaning a dataset, go to Home > Save As > Query Template (.pq) to reuse the same steps on future files.
- For large datasets, load only the columns and rows you need — it speeds up refresh and reduces file size.
Troubleshooting
- If you see "Expression.Error: We couldn't find the file" — check if the source file was moved, renamed, or deleted. Re-select the correct file in Get Data.
- If data types change after refresh — the source file may have new values that don’t match expected types (e.g., text in a number column). Go to Power Query Editor, check the column for unexpected values, and use Transform > Replace Values to fix them.
- If merging tables returns blank columns — verify the key columns have matching data types (e.g., both are Whole Number, not Text vs Number). Use the Data Type icon to fix mismatched types.
- If the refresh takes too long — reduce the number of steps, remove unused columns early, and avoid complex transformations in late steps. Use Filter to reduce rows before merging.
- If Power Query crashes or freezes — close Excel/Power BI, reopen, and try refreshing again. If it persists, simplify the query by removing steps one by one to isolate the issue.
- If you see "Data Source Error" — the source may require authentication (e.g., a database or web API). Click Edit Credentials in the Data Source Settings to enter correct login details.