Smart Systems for Home

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

Power Query Use Cases: Real Ways to Clean and Combine Data

· 6 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 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

  1. 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).
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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".
  7. 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.
  8. Filter rows: click the filter arrow in a column header, uncheck "(blank)" or specific values you want to exclude (e.g., "Cancelled" orders).
  9. 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.
  10. 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).
  11. 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.
  12. 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.

Frequently Asked Questions

Can Power Query work with databases like SQL Server or Access?

Yes. From Get Data, choose SQL Server, Access, or other database options. You’ll need permission to connect and valid credentials. Power Query pulls data without requiring SQL knowledge.

Can I combine data from different Excel files into one sheet?

Yes. Use From Folder to select all Excel files in a folder. Power Query detects tables within each file and combines them. Make sure each file has the same column structure.

Does Power Query work with live data feeds?

Yes. You can connect to web APIs, SharePoint lists, or online databases. Refresh the query to pull the latest data. Some sources require authentication or permissions.

Can I undo steps after closing Power Query?

No. Once you click Close & Load, the steps are saved but not editable in Excel. Reopen Power Query Editor by right-clicking the table and selecting Edit Query to modify steps.

What's the difference between Power Query in Excel and Power BI?

Functionally identical. Excel is for individual reports; Power BI is for dashboards and sharing. Both use the same engine, so queries can be copied between them.

Can Power Query handle 1 million rows of data?

Yes. Power Query is designed for large datasets. Excel may slow down when loading, but the transformation steps still run efficiently. Use Power BI Desktop for optimal performance with very large tables.