Filtering data with list inputs
A filter set up in the Power Query interface has its values written into the query, so changing them means editing the query. This page shows how to filter against a list kept in a worksheet table instead, so that anyone can change the criteria and refresh.
The example
Section titled “The example”The data is a short table of clothing items and quantities:

The aim is to remove every row whose Clothing value begins with Trousers or Shorts. Those two words should live in a separate table on the worksheet, where they can be changed without opening Power Query:

1. Load the list and the data
Section titled “1. Load the list and the data”- Load the Exclude table into Power Query. Its empty rows come through as nulls:

- Use the filter button on the column header to remove the nulls.
- Click the fx button beside the formula bar to add a step, and change its formula to the following, which takes the Exclude column out of the table as a list:
= #"Filtered Rows"[Exclude]The query now returns a list rather than a table:

- Name this query filterList.
- Load the clothing table into Power Query as a second query:

- Name this query Data.
2. Write a filter function
Section titled “2. Write a filter function”Each Clothing value has to be tested against every item in filterList, and a function is the natural way to repeat a test like that. Create a blank query and enter this code in the Advanced Editor:

The function works like this:
- Parameters. It takes two arguments:
rcd, which is a record holding one row of the data, andfield, which is the name of the field in that record to test. List.Transform. It goes through filterList and, for each item, tests whether the field’s value starts with that item, which gives a list of TRUE and FALSE values with one entry per item:- For Trousers-Short tested against {Trousers, Shorts}, the result is {TRUE, FALSE}.
- For T-Shirt-Medium, the result is {FALSE, FALSE}.
List.AnyTrue. It returns TRUE if any value in that list is TRUE, so the function as a whole returns TRUE when the value starts with any item in the list.- The underscore. Inside
Text.StartsWith, the_stands for the item of filterList thatList.Transformis currently testing.
Name the query fnStartsWithFilter.
3. Use the function to filter the data
Section titled “3. Use the function to filter the data”Go back to the Data query and add a custom column called Filter with this formula:

Here the _ stands for the current row of Data as a record, which is what the function’s first parameter expects, and "Clothing" names the field to test.
The new column shows TRUE for every row that matches the list:

- Because the matching rows are the ones to exclude, filter the Filter column to keep only FALSE.
- Remove the Filter column, which is no longer needed.
Only the rows that match nothing in the list remain:

4. Change the list and refresh
Section titled “4. Change the list and refresh”To check that the filter follows the list, change the Exclude table to Trousers and T-Shirt, then refresh the query. The output now holds the shorts instead:
