Smart Systems for Home

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

Power Query Filter Formula: Step-by-Step 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 filters rows with a formula by using the Filter rows button, which writes a Table.SelectRows step with a custom condition such as each [Status] = "Open". You can also type the formula directly into the formula bar or edit the generated step in the Advanced Editor. This guide shows the exact steps for both the ribbon and manual approaches, plus the mistakes that cause errors and how to fix them.

What You'll Need

  • Excel 2016 or later, or Power BI Desktop, with the Power Query Editor available (in Excel: Data > Get Data).
  • A table or data source already loaded into Power Query.
  • Basic familiarity with column names and the M language syntax used in Power Query formulas.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select any cell in your table and go to Data > Get Data > Launch Power Query Editor (or From Table/Range). In Power BI Desktop, click Transform Data on the Home ribbon. Menu labels can differ slightly by version and region.
  2. Load your data so the table appears in the left Queries pane and the preview shows your columns.
  3. Select the column you want to filter. Click the column header in the preview. This is optional for the formula approach but makes the generated step easier to read.
  4. Use the Filter rows button for a simple condition. Click the filter arrow on the column header, choose a condition such as Text Filters > Equals, and enter a value. Power Query adds a step named something like Filtered Rows and writes the formula for you.
  5. Inspect the generated formula. With the step selected in the Applied Steps pane, look at the formula bar. You will see something like = Table.SelectRows(PreviousStep, each [Status] = "Open"). The each keyword means the condition is applied to every row.
  6. Edit the formula directly for a custom filter. Click into the formula bar and change the condition. For example, to keep rows where the amount is greater than 100, type = Table.SelectRows(PreviousStep, each [Amount] > 100). Press Enter to apply. If the step name in the formula does not match the previous step, Power Query shows an error.
  7. Combine conditions with and or or. For example: each [Status] = "Open" and [Amount] > 100. Wrap each condition in parentheses when mixing and with or to control the order: each ([Status] = "Open" or [Status] = "Pending") and [Amount] > 100.
  8. Use the Advanced Editor for multi-line or complex filters. Go to Home > Advanced Editor. The full M script appears. You can edit the Table.SelectRows step there, which is easier for long conditions. Click Done to apply. If the editor reports a syntax error, check that every bracket and quote is closed.
  9. Filter for nulls and blanks. To keep rows where a column is empty, use each [Column] = null. To exclude nulls, use each [Column] <> null. Note that an empty text value "" is different from null; test both if your data mixes them.
  10. Filter by date ranges. Use each [OrderDate] >= #date(2024,1,1) and [OrderDate] < #date(2025,1,1). The #date literal is the correct way to write a date in M; typing a plain date string will not compare correctly.
  11. Rename the step for clarity. Right-click the step in Applied Steps and choose Rename. A descriptive name such as Filtered Open Orders makes the query easier to maintain.
  12. Check the result and load. The preview updates immediately. If the row count looks wrong, click the step above and below to compare. When satisfied, go to Home > Close & Load (Excel) or Close & Apply (Power BI) to load the filtered table.

Common Mistakes

  • Using the wrong step name. The first argument of Table.SelectRows must be the exact name of the previous step. Renaming a step without updating the formula breaks the query.
  • Forgetting the each keyword. Without each, Power Query tries to evaluate the condition once instead of per row, which causes an error or an unexpected result.
  • Comparing text to numbers. If a column is typed as text, [Amount] > 100 may fail or sort incorrectly. Change the column type first using the icon in the column header.
  • Mismatched quotes. M uses double quotes for text. Single quotes or smart quotes from copy-paste cause syntax errors.
  • Assuming null equals blank text. Filters that work for null will not catch "" and vice versa.
  • Editing the wrong step. Changes apply to the selected step and all steps after it. Select the correct step before editing the formula bar.

Tips

  • Use the formula bar as your primary editing surface for simple changes; it validates as you type.
  • Keep filter steps near the top of the query so later steps process fewer rows and refresh faster.
  • Use Text.Contains, Text.StartsWith, or Text.EndsWith for partial text matches, for example each Text.Contains([Email], "@example.com").
  • Comment complex conditions in the Advanced Editor with // so future you knows why the filter exists.
  • Test filters on a small sample first; a wrong condition can silently drop rows without an error.

Troubleshooting

If the filter step shows an error, click the step and read the message in the formula bar or the yellow error bar. The most common cause is a name mismatch or a type mismatch. Fix the step name first, then check column types. If the preview is empty when you expect rows, temporarily remove the filter by deleting the step (right-click > Delete) and inspect the raw data for leading spaces, different casing, or nulls. If the query is slow, move the filter earlier and remove unnecessary columns before filtering. If the Advanced Editor will not accept your change, compare bracket pairs and quote marks; M is strict about both. If a date filter fails, confirm the column is typed as Date, not Text, and use #date literals. If nothing works, close without saving, reopen the query, and rebuild the filter step using the ribbon button to get a known-good formula you can then modify.

Frequently Asked Questions

Can I filter with a formula instead of clicking the filter arrow?

Yes. Type or edit a Table.SelectRows formula in the formula bar or Advanced Editor. The ribbon button simply generates that same formula for you.

How do I filter for multiple values in one column?

Use or between conditions, or use List.Contains: each List.Contains({"Open","Pending"}, [Status]).

Why does my filter drop rows that look correct?

Usually a data type mismatch or hidden characters such as trailing spaces. Check the column type and use Text.Trim in a prior step.

Can I use a parameter in a filter formula?

Yes, if you have created a parameter query. Reference it by name in the condition, for example each [Region] = RegionParam.

Does filtering in Power Query change the original data?

No. Power Query filters only the loaded query result; the source table or file is unchanged.