List.Select
Keeps only the items in a list for which a condition is true.
List.Select(list, selection)Returns: A list with the matching items, in their original order.
What it does
List.Select runs a test on every item and keeps the ones that pass. It is the list version of a filter. Use it to pull out the amounts above an approval limit, the dates in a period, or the names that match a rule, without writing a full table query.
Syntax and arguments
list: the list to search.selection: a function that returnstrueto keep an item andfalseto drop it.eachis the usual form, with_standing for the item.
Example
A company requires a second approver for any payment of 5,000 or more. The AP team has a list of payment amounts for the week and wants only the ones that need a second approver.
let
Payments = {120, 4500, 80, 9000, 5000},
NeedsApproval = List.Select(Payments, each _ >= 5000)
in
NeedsApproval
The result is the list {9000, 5000}. Items below 5,000 are dropped and the rest keep their order. With a table, the same idea is Table.SelectRows, which works on whole rows.
Example: a second, different use
Keeping only text values that look like invoice numbers: List.Select(Codes, each Text.StartsWith(_, "INV-")).
Things to watch
- A test that returns null is not
true, so the item is dropped. Handle blanks first witheach _ <> null and _ >= 5000or remove them with List.RemoveNulls. - List.Select does not change the items, only which ones remain. Chain it with List.Transform to change them.
- Check the type of your list before you compare. Text values such as "5000" and the number 5000 are not the same thing in a comparison, so convert the column first with Number.FromText or a type step.
- For very long lists read from a database, filter the table in the source query so the work happens on the server.
In business terms
Approval limits, duplicate checks, aging buckets and exception reports often start with a filter. List.Select is the quick version for a single column of values. Use Table.SelectRows when you need to keep the rest of each row.