Smart Systems for Home

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

Power Query Filter Based on List: Step-by-Step Guide

· 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

To filter a Power Query table based on a list of values, you create a list query (or use a list literal) and then filter the main table using the List.Contains function in a custom column or by merging with the list. The simplest method is to add a custom step that keeps only rows where a column's value appears in your list. This works in Excel and Power BI Desktop, and the exact menu labels can differ slightly by version and region.

What You'll Need

  • Excel (Microsoft 365 or Excel 2016+) or Power BI Desktop with Power Query available.
  • A table loaded into Power Query (Data > From Table/Range in Excel, or Get Data in Power BI).
  • Your list of values — either typed directly, in a separate table, or in a named range.
  • Basic familiarity with the Power Query Editor and the formula bar.

Step-by-Step

  1. Load your main table into Power Query. In Excel, select your data range and go to Data > From Table/Range. In Power BI Desktop, use Home > Get Data > Excel workbook (or another source) and then Transform Data. The Power Query Editor opens.
  2. Create a list query (optional but recommended for long lists). If your list is in a worksheet table, load that table into Power Query as a separate query. Name it something like FilterList. If your list is short, you can skip this and type it directly in a later step.
  3. Decide on the filter column. In your main query, identify the column you want to filter (for example, CustomerID or Region). Click that column header to select it.
  4. Add a custom column with List.Contains. Go to Add Column > Custom Column. In the formula box, enter a formula like:
    List.Contains(FilterList, [CustomerID])
    Replace FilterList with the name of your list query (or a list literal such as {"North","South","East"}), and [CustomerID] with your actual column name. This returns true if the value is in the list, false otherwise. Click OK.
  5. Filter the new column to true. Click the filter arrow on the new custom column and select true (or True). Only rows whose values appear in the list remain.
  6. Remove the helper column (optional). Right-click the custom column header and choose Remove to keep the table clean.
  7. Apply and close. In Excel, click Close & Load (or Close & Load To). In Power BI, click Close & Apply. The filtered table loads into your worksheet or data model.

If your list is in a separate query, an alternative is to use Home > Merge Queries and join the main table to the list query on the matching column, using an inner join. This keeps only matching rows and is often faster for very large lists. After merging, expand only the columns you need and remove the merge helper column.

Common Mistakes

  • Using the wrong list syntax. A list literal uses curly braces and commas: {"A","B","C"}. Text values need quotes; numbers do not. Mixing types causes errors.
  • Referencing the list query incorrectly. The list query must be loaded and named exactly as referenced in the formula. If you rename it later, update the formula.
  • Filtering on the wrong data type. If your column is numeric but your list contains text (or vice versa), List.Contains may return false for everything. Ensure both sides use the same type.
  • Case sensitivity. By default, List.Contains is case-sensitive for text. If your data has mixed casing, use List.Contains with a comparer, or standardise case with Text.Upper or Text.Lower before filtering.
  • Forgetting to apply changes. Steps in the editor are not applied to the worksheet or model until you close and load.

Tips

  • Keep your list query as Connection Only so it does not create an extra table in the worksheet.
  • For long lists, load the list from a table rather than typing it into the formula — it is easier to maintain.
  • Use List.ContainsAny if you need to match against multiple lists, or List.ContainsAll for AND logic.
  • If you frequently change the list, consider using a parameter or a named range so you can update it without editing the query.
  • Test with a small sample first to confirm the filter behaves as expected before applying to the full dataset.

Troubleshooting

If the filter returns no rows, check that the list query contains the values you expect and that the column names match exactly. If you see an error like “We cannot convert a value of type Text to type List”, your list literal is malformed — ensure curly braces and commas are correct. If the custom column shows errors, click the error cell to see the message; often it is a type mismatch or a missing list query. If performance is slow with a very large list, switch to the merge method instead of a custom column. If the list query was deleted or renamed, the main query will fail to refresh; restore the query or update the formula. Finally, if changes do not appear after Close & Load, refresh the query (Data > Refresh All in Excel, or Refresh in Power BI).

Frequently Asked Questions

Can I filter using a list from a worksheet cell range?

Yes. Load that range as a table into Power Query, name the query, and reference it in List.Contains. Alternatively, use a named range and reference it directly if your version supports it.

Does List.Contains work with numbers and dates?

Yes, as long as the list and the column are the same data type. For dates, use date literals like #date(2024,1,1).

How do I make the filter case-insensitive?

Use List.Contains with Comparer.OrdinalIgnoreCase as the third argument, or convert both the column and list to the same case before filtering.

Can I use a list to exclude rows instead of include them?

Yes. Add a custom column with not List.Contains(...) and filter to true, or filter the original column to false after applying the contains filter.

What is the difference between List.Contains and merging?

List.Contains checks each row against a list and is simple for short lists. Merging joins two tables and is generally more efficient for large lists or when you need additional columns from the list table.

Will the filter update if I change the list later?

Yes, as long as the list query is refreshed. In Excel, use Refresh All; in Power BI, use Refresh. The main query will re-evaluate the filter against the updated list.