Smart Systems for Home

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

Power Query Table.ContainsAny: How to Use It

· 5 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 does not have a built-in function called Table.ContainsAny. To test whether a table contains any of several values in a column, you combine List.ContainsAny with Table.Column and wrap the result in Table.AddColumn. The shortest working pattern is: Table.AddColumn(Source, "Match", each List.ContainsAny(Table.Column(Source, "ColumnName"), {"value1", "value2"}), type logical). This adds a true/false column that flags rows where the target column holds at least one of the listed values. The steps below walk through it in the Power Query Editor, including how to handle case sensitivity and nulls.

What You'll Need

  • Power BI Desktop, Excel with Power Query (Data > Get Data), or Analysis Services with Power Query — the editor is the same across these hosts, though menu labels can differ slightly by version and region.
  • A table already loaded into Power Query, with the column you want to test identified by name.
  • The list of values you want to search for, written exactly as they appear in your data (or in the case you want to match, depending on the comparer you choose).

Step-by-Step

  1. Load your table into Power Query. In Excel, select your data and go to Data > From Table/Range. In Power BI Desktop, use Home > Get Data and pick your source. Confirm the table appears in the Power Query Editor with a header row.
  2. Open the Advanced Editor. On the Home tab, click Advanced Editor. This shows the M code behind your query. If you prefer the ribbon, you can add the step through Add Column > Custom Column instead, but the Advanced Editor gives you full control over the function syntax.
  3. Find the last step name. At the bottom of the query, note the name of the final step (often Source or Changed Type). You will reference it in the new step.
  4. Add a new step using Table.AddColumn and List.ContainsAny. Insert a line before the final in clause, for example: Matched = Table.AddColumn(Source, "Contains Any", each List.ContainsAny(Table.Column(Source, "Product"), {"Apple", "Banana", "Cherry"}), type logical) Replace Source with your last step name, Product with your column name, and the list with your search values. Then change the in clause to return Matched.
  5. Click Done. Power Query validates the syntax. If there is an error, the message usually points to a misspelled column name or a missing comma.
  6. Check the new column. The result is a column of true/false values. Use the column filter dropdown to keep only true rows if you want to isolate matches.
  7. Handle case sensitivity. By default, List.ContainsAny is case-sensitive. To ignore case, add a comparer as the third argument: List.ContainsAny(Table.Column(Source, "Product"), {"apple", "banana"}, Comparer.OrdinalIgnoreCase). This is the most common adjustment.
  8. Handle nulls. If the column contains nulls, List.ContainsAny returns false for those rows rather than an error, which is usually the behaviour you want. If you need to treat null as a match, add null to the list.
  9. Apply and close. Click Close & Load (Excel) or Close & Apply (Power BI) to send the result back to your workbook or model.

Common Mistakes

  • Looking for Table.ContainsAny in the function list. It does not exist. The correct building blocks are Table.Column and List.ContainsAny.
  • Passing the whole table instead of a column. List.ContainsAny expects a list, so you must extract the column first with Table.Column.
  • Forgetting the type argument. Table.AddColumn needs a type (for example type logical) or the column may come back as any, which breaks later steps.
  • Assuming case-insensitive matching. The default is case-sensitive; add Comparer.OrdinalIgnoreCase when you need it.
  • Using the wrong step name. If you reference Source after several transformation steps, you test the original data, not the cleaned data. Always reference the most recent step.

Tips

  • Store your search values in a separate query and reference it as a list, so you can update the list without editing code.
  • Use List.Contains instead of List.ContainsAny when you only need to test a single value.
  • For partial matches (for example, any product name containing "App"), use rather than List.ContainsAny, which requires exact values.
  • Name the new step descriptively (for example FlaggedMatches) so the Applied Steps pane stays readable.
  • Test on a small sample first; a logical column is cheap, but a wrong list can silently filter out rows.

Troubleshooting

  • "The field 'X' of the record wasn't found." The column name in Table.Column does not match the actual header. Check spelling and case, and confirm the step you reference still has that column.
  • All results are false. Check case sensitivity first, then confirm the values in your list match the data exactly (no trailing spaces). Use Text.Trim in a prior step if needed.
  • Expression.Error about a list. You likely passed a table or a single text value where a list is required. Wrap values in curly braces: {"A", "B"}.
  • The column shows errors instead of true/false. Remove the type argument or set it to type logical; a mismatched type causes conversion errors.
  • Changes do not appear after Close & Load. Refresh the query; Power Query caches results, and the preview may not match the loaded table until refresh.
  • If that did not work, simplify: create a custom column with just List.ContainsAny(Table.Column(Source, "Column"), {"test"}) and inspect the output before adding the full list or comparer.

Frequently Asked Questions

Is there a real Table.ContainsAny function in Power Query?

No. The M library provides List.ContainsAny, and you apply it to a table column via Table.Column inside Table.AddColumn.

How do I make the match case-insensitive?

Pass Comparer.OrdinalIgnoreCase as the third argument to List.ContainsAny.

Can I search for partial text instead of exact values?

Yes, but use Text.Contains with List.AnyTrue or List.Transform; List.ContainsAny matches whole values only.

Does List.ContainsAny handle nulls?

It returns false for null entries unless null is included in the list.

Can I use a column from another query as the value list?

Yes. Reference the other query and convert its column to a list, for example with Table.Column, then pass that list to List.ContainsAny.

Why does my new column show as text instead of true/false?

The type argument in Table.AddColumn was omitted or set incorrectly. Set it to type logical.