Smart Systems for Home

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

Excel Power Query Functions: A How-To Guide

· 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 functions let you clean, transform, and combine data in Excel using a repeatable, step-by-step process instead of manual copy-paste. The core idea is simple: you connect to data, apply transformations, and load the result to a worksheet or the Data Model. Everything you do is recorded as steps, so you can refresh later and the same logic runs again. To get started, you need Excel 2016 or later (or Microsoft 365) on Windows or Mac. Power Query is built in under the Data tab. No add-in is required for most versions, though older Excel 2010/2013 need the free Power Query add-in from Microsoft. You should also have your source data ready — a table in a worksheet, a CSV file, a folder of files, or a database connection.

What You'll Need

  • Excel 2016 or later, or Microsoft 365 (Windows or Mac). Power Query is on the Data tab.
  • Source data: an Excel table, CSV, text file, folder, or database you can access.
  • Basic familiarity with Excel tables and column headers.
  • Optional: Power Query add-in for Excel 2010/2013 (download from Microsoft).

Step-by-Step

  1. Format your source as a table. Select your data range and press Ctrl+T (Windows) or Command+T (Mac). Ensure the table has headers. Give the table a meaningful name in Table Design. This makes it easy to reference later.
  2. Open Power Query Editor. Go to the Data tab and click “From Table/Range” (or “From Text/CSV”, “From Web”, etc., depending on your source). The Power Query Editor opens in a separate window. Note: menu labels can differ slightly by Excel version and platform.
  3. Review the applied steps. On the right side, the “Applied Steps” pane lists each transformation. You can click any step to see the data at that point. To remove a step, click the X next to it. Steps run in order.
  4. Clean and shape the data. Use the ribbon tabs: Home, Transform, Add Column, View. Common actions: remove columns (right-click column header > Remove), change data types (click the icon left of the column header), filter rows (dropdown arrow), split columns (Transform > Split Column), and replace values (Transform > Replace Values). Each action adds a step.
  5. Use functions in custom columns. To apply a function, go to Add Column > Custom Column. In the formula box, you can write M code using built-in functions. For example, to extract the year from a date column named “OrderDate”, enter: Date.Year([OrderDate]). To trim text: Text.Trim([CustomerName]). To convert text to number: Number.FromText([Amount]). Click OK. The new column appears and a step is added.
  6. Combine data from multiple sources. Use Home > Append Queries to stack tables with the same columns, or Home > Merge Queries to join tables on a key column (like a VLOOKUP but more robust). Choose the join kind (Inner, Left Outer, etc.). Expand the merged column to bring in needed fields.
  7. Handle errors. If a step produces errors, you’ll see “Error” in cells. Click the error to see details. Use Transform > Replace Errors to substitute a value, or Remove Errors to filter them out. For custom columns, wrap functions in try ... otherwise ... to handle exceptions, e.g., try Number.FromText([Amount]) otherwise null.
  8. Load the result. When done, click Home > Close & Load. Choose “Close & Load” to load to a new worksheet, or “Close & Load To…” to load to the Data Model or an existing worksheet. The query runs and outputs a table.
  9. Refresh later. When source data changes, right-click the output table and choose Refresh, or use Data > Refresh All. Power Query re-runs all steps. If you change the query, go to Data > Queries & Connections, right-click the query, and choose Edit to reopen the editor.

Common Mistakes

  • Not setting data types. Power Query often auto-detects types, but it can be wrong. Always check and set types explicitly (especially dates and numbers) to avoid errors in later steps.
  • Assuming steps are dynamic. Steps reference column names as they were at that point. If you rename a column earlier, later steps may break. Rename columns early and consistently.
  • Using custom columns when a built-in transform exists. For simple tasks like trimming or splitting, use the ribbon buttons — they generate cleaner, more maintainable steps.
  • Forgetting that Power Query is case-sensitive in some functions. Text comparisons may be case-sensitive depending on the function. Use Text.Lower or Text.Upper to normalize if needed.
  • Loading to the wrong place. Loading to a worksheet creates a table; loading to the Data Model is better for large data or when using PivotTables. Choose deliberately.

Tips

  • Name your query steps descriptively: double-click a step name in Applied Steps to rename it. This makes complex queries easier to debug.
  • Use the Advanced Editor (Home > Advanced Editor) to view and edit the full M code. It’s useful for copying logic between queries.
  • When merging, ensure the key columns have the same data type. Mismatched types cause errors or empty results.
  • For repeated transformations across many files, use “From Folder” and combine files. Power Query can combine all files in a folder with the same structure.
  • Document your query with comments in the Advanced Editor using // for single-line or /* */ for blocks.

Troubleshooting

  • Query won’t refresh: Check that the source file path hasn’t changed, and that you have permission to access it. Use Data > Queries & Connections > right-click query > Edit to see which step fails.
  • Errors after changing source columns: If you renamed or removed a column in the source, steps referencing the old name will fail. Edit the step to point to the new name, or delete and recreate the step.
  • Data type errors: A column may contain mixed types (e.g., text and numbers). Use Transform > Data Type > Using Locale to specify the correct format, or clean the data first.
  • Merge returns no matches: Check for leading/trailing spaces (use Text.Trim) and ensure both key columns are the same type. Also verify case sensitivity if using text keys.
  • Performance is slow: Reduce the number of rows early with filters, remove unnecessary columns, and avoid complex custom columns when simpler transforms work.

Frequently Asked Questions

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

No. Most transformations can be done through the ribbon. M code is only needed for advanced custom logic.

Can I use Power Query on Mac?

Yes, Power Query is available in Excel 2016 for Mac and later, though some features may be limited compared to Windows.

What’s the difference between Power Query and Power Pivot?

Power Query is for extracting, transforming, and loading data. Power Pivot is for data modeling and creating relationships. They often work together.

How do I edit a query after loading it?

Go to Data > Queries & Connections, right-click the query, and choose Edit. Make changes, then Close & Load again.

Can Power Query combine data from multiple Excel files?

Yes. Use Data > Get Data > From File > From Folder, then combine the files. All files must have the same structure.

Why does my query show “Download did not complete” error?

This often happens with web sources or large data. Check your internet connection, reduce the data size, or try loading to the Data Model instead of a worksheet.