Smart Systems for Home

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

Power Query Table.SelectRows Guide and Examples

· 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

The Table.SelectRows function in Power Query is used to filter a table by keeping only the rows that meet specific logical criteria. To use it, you apply a predicate function (a logical test) to each row; if the test returns true, the row is kept; if it returns false, the row is removed. This is the engine behind the "Filter" dropdowns in the Power Query Editor interface.

What You'll Need

  • A dataset loaded into the Power Query Editor (Excel or Power BI).
  • A basic understanding of M language syntax (case-sensitivity is critical).
  • A table with defined column headers and data types (Text, Number, or Date).

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
  2. Identify Your Target Column: Locate the column you wish to filter. Note the exact spelling and capitalization of the column header, as Table.SelectRows requires an exact match.
  3. Apply a Basic Filter via the UI: Click the filter arrow in the column header. Uncheck the values you want to remove or use Text Filters / Number Filters to set a rule (e.g., "Greater Than"). This automatically generates a Table.SelectRows step in the formula bar.
  4. Access the Formula Bar: If the formula bar is not visible, go to the View tab and check the Formula Bar box. You will see a formula similar to = Table.SelectRows(#"Previous Step", each ([ColumnName] = "Value")).
  5. Manually Edit for Advanced Logic: To create more complex filters, click into the formula bar. The each keyword is a shorthand for a function that iterates through every row. Replace the simple equality check with logical operators: and, or, and not.
  6. Implement Multiple Criteria: To filter for rows where a value is greater than 10 AND less than 20, write: = Table.SelectRows(#"Previous Step", each [Amount] > 10 and [Amount] < 20).
  7. Filter for Multiple Text Options: To keep rows that match one of several specific values, use the List.Contains function inside the select rows statement: = Table.SelectRows(#"Previous Step", each List.Contains({"North", "South", "East"}, [Region])).
  8. Handle Null Values: If your data contains nulls, use the <> null operator to exclude them: = Table.SelectRows(#"Previous Step", each [CustomerName] <> null).
  9. Apply the Changes: Once the formula is entered, press Enter. The preview window will refresh to show only the rows that satisfy the condition.

Common Mistakes

The most frequent error is ignoring case sensitivity. In Power Query M, "Apple" is not the same as "apple". If your filter returns zero rows but you can clearly see the data in the table, check the capitalization of both the column name and the value you are filtering for.

Another common mistake is the misuse of the or operator. Users often write each [Status] = "Open" or "Pending". This is syntactically incorrect. The correct way to write this is each [Status] = "Open" or [Status] = "Pending". Every condition must be a complete logical statement.

Incorrect data type referencing is also a hurdle. Attempting to use a numeric operator (like >) on a column formatted as Text will result in an Expression.Error. Ensure the column type is set to Decimal Number or Whole Number before applying numeric filters.

Finally, many users forget that Table.SelectRows creates a new table based on the previous step. If you rename a column in an earlier step but do not update the column name inside the Table.SelectRows function, the query will break because it cannot find the original column name.

Tips

Use Parameters for Dynamic Filtering: Instead of hard-coding a value like "North", create a Power Query Parameter. Replace the hard-coded text with the parameter name: = Table.SelectRows(#"Previous Step", each [Region] = ParameterRegion). This allows you to change the filter without opening the Query Editor.

Combine with Text.Contains: For partial matches, use Text.Contains. For example, to find any row where a description contains the word "Urgent", use: = Table.SelectRows(#"Previous Step", each Text.Contains([Description], "Urgent")). To make this case-insensitive, add Comparer.OrdinalIgnoreCase as the third argument: Text.Contains([Description], "Urgent", Comparer.OrdinalIgnoreCase).

Optimize Performance with Query Folding: When connecting to SQL databases, Table.SelectRows usually "folds." This means Power Query converts the M code into a SQL WHERE clause and sends it to the server. To keep folding active, place your Table.SelectRows steps as early as possible in the query sequence, before you perform complex transformations like merging or custom column additions.

Filtering Dates: Use Date.IsInPreviousMonth or Date.IsInCurrentYear for dynamic date ranges. For example: = Table.SelectRows(#"Previous Step", each Date.IsInPreviousMonth([OrderDate])). This ensures your report always shows the most recent data without manual updates.

Troubleshooting

Issue: The filter returns an empty table.
First, check for leading or trailing spaces in your data. A value that looks like "Active" might actually be "Active ". Use the "Trim" transformation on the column before applying Table.SelectRows. Second, verify the case sensitivity of the text string.

Issue: Error message "We cannot convert the value ... to type Logical".
This happens when the expression inside Table.SelectRows does not result in a true or false value. Ensure you are using comparison operators (=, <>, >, <) and not just referencing a column name. For example, each [IsActive] works if the column is already a True/False type, but each [Status] will fail because "Status" is text, not a logical boolean.

Issue: The query is running extremely slowly.
If you are filtering a massive dataset, check if Query Folding is broken. Right-click the Filtered Rows step in the Applied Steps pane. If "View Native Query" is greyed out, the filter is being processed on your local machine rather than the server. Try moving the filter step higher up in the list of transformations.

Issue: "The column 'X' of the table wasn't found".
This occurs if a previous step changed the column name or removed the column. Check the step immediately preceding Table.SelectRows to ensure the column name matches exactly what is written in the formula.

Frequently Asked Questions

Can I filter for multiple columns at once?

Yes. You can use and or or to combine criteria from different columns, such as each [Region] = "West" and [Sales] > 1000.

Does Table.SelectRows delete data from the source?

No. Power Query is a non-destructive transformation layer. It only filters what is loaded into the model; your original source file or database remains untouched.

How do I filter for a list of values from another table?

You can use the List.Contains function combined with a list generated from another table, or more simply, perform an Inner Join (Merge) between the two tables to keep only matching rows.

Is there a way to filter rows based on the current date?

Yes, use DateTime.LocalNow() or Date.From(DateTime.LocalNow()) within the expression to compare a column to today's date.

Can I use wildcards like * or % in Table.SelectRows?

M does not use standard SQL wildcards. Instead, use Text.StartsWith, Text.EndsWith, or Text.Contains to achieve the same result.