Power Query List.Contains: A How-To Guide
In this article
List.Contains checks whether a specific value exists inside a Power Query list and returns true or false. The syntax is List.Contains(list as list, value as any, optional equationCriteria as any) as logical. You need Power Query Editor open (in Excel via Data > Get Data, or in Power BI via Transform data) and a query that already produces or references a list. That is the whole requirement; no add-ins or special permissions are involved.
What You'll Need
- Excel (Microsoft 365 or 2019+) or Power BI Desktop with Power Query Editor available.
- A query containing a list, or a step that generates one (for example, a column reference converted to a list, or a manually typed list).
- Basic familiarity with the Power Query formula bar and the Advanced Editor, since List.Contains is a function you type rather than a button you click.
Step-by-Step
- Open Power Query Editor. In Excel, select any cell in your data and go to Data > Get Data > Launch Power Query Editor (labels vary slightly by version and region). In Power BI Desktop, use Home > Transform data.
- Identify or create the list you want to search. A list in Power Query is anything wrapped in curly braces, such as
{"Red", "Green", "Blue"}. If you have a table column, you can convert it to a list withTable.Column(Source, "ColumnName")or by right-clicking the column header and choosing Drill Down (which produces a list when the column has multiple values). - Add a custom step in the formula bar. With the step you want to build on selected in the Applied Steps pane, click the formula bar (or use Home > Advanced Editor for a multi-line edit) and type a new step name followed by the function. For example:
CheckRed = List.Contains(MyList, "Red"). Press Enter. The result is a single logical value, true or false. - Use it inside a table transformation when you need a column of results. To test every row against the same list, add a custom column: go to Add Column > Custom Column, name it, and enter a formula such as
List.Contains({"Red", "Green"}, [Color]). Each row is evaluated separately and returns true or false. - Filter or branch on the result. A logical result can drive a filter (click the filter arrow on the new column and keep only TRUE) or a conditional column (Add Column > Conditional Column) so you can label matches and non-matches.
- Handle case sensitivity deliberately. By default, List.Contains is case-sensitive for text. To make it case-insensitive, wrap the value or list in Text.Lower (or Text.Upper) before comparing, for example
List.Contains(MyList, Text.Lower([Color]))with the list also lowercased. Do not assume the function ignores case. - Check your work. Select the new step in Applied Steps and confirm the preview shows the expected true/false values. If the step errors, read the message in the yellow bar; it usually names the argument that is the wrong type.
- Load or close and apply. In Excel, choose Home > Close & Load to send the result to a worksheet or data model. In Power BI, choose Home > Close & Apply.
Common Mistakes
- Passing a table instead of a list. List.Contains expects a list. A whole table or a record will produce a type error. Convert the column with Table.Column or drill down first.
- Assuming case-insensitive matching. Text comparisons are case-sensitive unless you normalise case with Text.Lower or Text.Upper on both sides.
- Forgetting that numbers and text are different types.
List.Contains({1, 2, 3}, "1")returns false because the list holds numbers, not text. Convert with Number.From or Text.From as appropriate. - Using it where List.ContainsAny or List.ContainsAll is needed. List.Contains checks one value against a list. To check whether any of several values appear, use List.ContainsAny(list, values). To check that all appear, use List.ContainsAll(list, values).
- Typing the function into a cell rather than the formula bar. List.Contains is a Power Query (M) function. It does not exist as a worksheet function and will not work in a normal Excel cell.
- Ignoring nulls. A null in the value argument returns false rather than an error in most cases, which can silently hide missing data. Filter or replace nulls before testing if that matters to your logic.
Tips
- Use equationCriteria when you need custom comparison logic. The third argument accepts a comparer such as Comparer.OrdinalIgnoreCase, which gives you case-insensitive matching without changing your data:
List.Contains(MyList, "red", Comparer.OrdinalIgnoreCase). - Name your steps clearly (for example,
IsPreferredColor) so the Applied Steps pane reads like a summary of your logic. - For large tables, keep the comparison list as a single step rather than rebuilding it inside every row; Power Query can reuse the step reference.
- Combine List.Contains with List.Select or List.Transform when you need to keep or change only the matching items in a list.
- Test with a tiny sample first (three or four values) before applying the step to a large query, so errors are easy to spot.
Troubleshooting
If the step shows an error, click the error message to see the detail. A type mismatch almost always means the list and the value are different data types; convert one side to match the other. If the result is always false when you expect true, check case, leading or trailing spaces (use Text.Trim), and whether the list actually contains the value you think it does by previewing the list step. If the function name is underlined in red, you may have typed it in the wrong place or misspelled it; the M language is case-sensitive, so List.Contains must be capitalised exactly. If the query is slow, check whether you are rebuilding the list inside a per-row custom column; move the list to its own step and reference it. If nothing resolves the error, delete the failing step and rebuild it in the Advanced Editor, which gives a clearer view of the full expression.
Frequently Asked Questions
Is List.Contains case-sensitive?
Yes, by default. Use Text.Lower or Text.Upper on both sides, or pass Comparer.OrdinalIgnoreCase as the third argument, to make it case-insensitive.
What is the difference between List.Contains and List.ContainsAny?
List.Contains checks for one value. List.ContainsAny returns true if any of several values appear in the list, and List.ContainsAll requires all of them to appear.
Can I use List.Contains in a calculated column in Power BI?
Not directly in DAX. It is an M function used inside Power Query. In DAX you would use CONTAINS or a similar function instead.
Why does List.Contains return false for a number I can see in the list?
The list likely holds text values such as "1" rather than the number 1. Convert one side with Number.From or Text.From so the types match.
Does List.Contains work with null values?
It can, but results can be surprising. Replace or filter nulls first if your logic depends on them, and test with a small sample.
Can I search a list of records?
Yes, but you need to supply a record as the value argument and, if you want to match on a field, use equationCriteria or extract the field into a separate list first.