Smart Systems for Home

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

Power Query List.Select Function: 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 List.Select function in Power Query is used to filter a list down to only those items that meet a specific condition. It achieves this by iterating through every element in a provided list and applying a logical test (a predicate); if the test returns true, the item is kept, and if it returns false, the item is discarded. This is the fundamental way to perform conditional filtering when working with lists rather than tables in the Power Query M formula language.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • Access to the Power Query Editor.
  • A basic understanding of how to open the Advanced Editor or use the Formula Bar.
  • An existing list of data (this could be a column converted to a list or a manually defined list).

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 List: Ensure you are working with a List object, not a Table. In Power Query, a List is indicated by a simple vertical column of values without a header, and the icon in the Queries pane looks like a small list rather than a table grid. If you have a table, you can right-click a column header and select Remove Other Columns, then right-click the remaining column and select Drill Down to convert it into a list.
  3. Insert a Custom Step: Click the fx icon next to the formula bar. This creates a new step in your Applied Steps list.
  4. Write the Function Syntax: In the formula bar, type the function using the following structure: = List.Select(ListName, each [Condition]). Replace ListName with the name of the previous step (e.g., Source or Custom1) and [Condition] with your logical test.
  5. Define the Logical Condition: Use the each keyword to tell Power Query to evaluate every single item in the list. For example, if you have a list of numbers and only want those greater than 10, your formula would be: = List.Select(Source, each _ > 10). The underscore (_) represents the current item being evaluated.
  6. Apply Complex Logic (Optional): If you need multiple conditions, use and or or. For instance, to find numbers between 10 and 20, use: = List.Select(Source, each _ > 10 and _ < 20).
  7. Execute and Verify: Press Enter. The preview window will now show only the items that satisfied your condition.

Common Mistakes

One of the most frequent errors is forgetting the each keyword. In M, List.Select requires a function as its second argument. The each keyword is a shorthand way of writing a function (a lambda expression). Without it, Power Query will throw an error because it expects a function but finds a logical expression instead.

Another common mistake is case sensitivity. Power Query is strictly case-sensitive. If you are filtering a list of text values using each _ = "Complete", any items that are "complete" (lowercase 'c') will be filtered out. To avoid this, users often wrap the item in a transformation function, such as each Text.Lower(_) = "complete".

Users also frequently confuse List.Select with Table.SelectRows. While they perform similar logical tasks, List.Select only works on List objects. If you attempt to use it on a Table object, the query will fail. You must either drill down to a list first or use the table-specific function.

Finally, attempting to use the underscore (_) outside of an each block or a defined function will result in a syntax error. The underscore is a placeholder that only has meaning within the context of a function's iteration.

Tips

To handle null values, always include a null check in your condition. If your list contains nulls and you perform a comparison like _ > 10, the result for the null item is not false, but null. While List.Select generally treats null as false, being explicit with each _ <> null and _ > 10 ensures your logic is robust and prevents unexpected behavior in complex nested queries.

For text-based lists, use Text.Contains inside List.Select for more flexible filtering. Instead of looking for an exact match, you can find any item that contains a specific substring: = List.Select(Source, each Text.Contains(_, "Keyword")). This is significantly more powerful than simple equality checks.

If you find yourself writing very long conditions, consider creating a separate custom function in the Power Query editor and referencing that function inside List.Select. This keeps your main query clean and makes the logic reusable across different lists in the same workbook.

When working with large datasets, remember that List.Select is an iterative process. If you are filtering a list that is derived from a database query, try to perform the filtering at the source (SQL level) via Table.SelectRows before converting to a list. This allows for "Query Folding," where the server does the heavy lifting rather than your local machine's memory.

Troubleshooting

If you receive a , it is almost certainly because the each keyword is missing from the second argument of your List.Select function. Ensure the formula looks like List.Select(List, each ... ) .

If the function runs but returns an empty list when you expect results, check for trailing or leading spaces in your data. Text values that look identical but have a hidden space at the end will fail an equality test. Use Text.Trim(_) within your condition to remove these spaces: = List.Select(Source, each Text.Trim(_) = "TargetValue").

If you encounter a Value.Error regarding data types, ensure the list contains the data type you are testing against. For example, if you use _ > 10 on a list that contains both numbers and text, Power Query will error when it hits a text string. You can wrap the item in Value.FromText or use try ... otherwise logic to skip incompatible types: = List.Select(Source, each try _ > 10 otherwise false).

If the query is performing very slowly, check if you are calling List.Select inside another iterative function (like List.Transform). This creates an O(n^2) complexity problem. Try to sort your data or use a different approach, such as joining tables, to reduce the number of iterations required.

Frequently Asked Questions

Can I use List.Select to filter a table?

No, List.Select is designed specifically for List objects. To filter a table, you should use Table.SelectRows, which follows a very similar syntax but operates on table rows instead of individual list items.

How do I filter for multiple specific values?

The most efficient way to filter for a set of values is to use List.Contains. Instead of writing each _ = "A" or _ = "B" or _ = "C", you can create a separate list of allowed values and use = List.Select(Source, each List.Contains({"A", "B", "C"}, _)).

Is List.Select case-sensitive?

Yes, the M language is case-sensitive. If you are comparing text, "Apple" and "apple" are considered different. Use Text.Lower or Text.Upper on both sides of the comparison to perform a case-insensitive search.

What is the difference between List.Select and List.Filter?

In Power Query M, List.Filter does not exist as a standard function; List.Select is the correct function for filtering lists. If you see "Filter" in the user interface, Power Query is usually generating Table.SelectRows or List.Select code in the background.

Can I use List.Select with dates?

Yes, you can use standard date comparison operators. For example, = List.Select(Source, each _ > #date(2023, 1, 1)) will return all dates in the list that occur after January 1st, 2023.

How do I select only the top 10 items after filtering?

You can wrap the List.Select function inside a List.FirstN function. For example: = List.FirstN(List.Select(Source, each _ > 10), 10). This filters the list first and then takes the first 10 results from that filtered set.