Filtering in Power Query is straightforward when we know exactly which values to keep. Select a few items from a column’s filter menu, click OK, and we’re done.
But there’s a catch: those selections are hard-coded into the M code. If we want different values next time, we have to edit the query.
A list gives us a more flexible approach. We can maintain our filter values in an Excel table, refresh the query, and let Power Query return the matching records. We can also use a list to choose output columns or calculate the filter values from the data itself.
There are four useful methods:
- Filter rows with
List.Contains. - Use a merge for a simple, potentially faster alternative.
- Filter output columns using a list of column names.
- Build a dynamic list from the data, then use it to filter the original rows.
What You'll Learn
- Use List.Contains to include or exclude rows based on a separate filter list.
- Consider a merge for simple matching scenarios where refresh performance matters.
- Control output column selection and order with a list of column names.
- Calculate a filter list from grouped data to return dynamically selected detailed records.
Set up the example data
Our examples use an Excel data table in cells A1:E17 with five columns: Date, Item, Model, Region, and Value.
Alongside the data, we have two small Excel tables:
- Filter list: The Item values we want to include, initially Alpha and Charlie.
- Column list: The column names we want in the output, initially Date, Item, Region, and Value.
To load each table into Power Query, click inside it and select Data > From Table/Range. Repeat for all three tables.
For the formulas below, we’ll call the queries Data, FilterList, and ColumnList. The filter table’s column is named Filter List, and the column-selection table’s column is named Column List. Substitute your own names where necessary.
1. Filter rows using List.Contains
Understand what a row filter actually does
Start in the Data query. Open the Item column’s filter menu, select Alpha and Charlie, and click OK.
Power Query creates a step like this:
= Table.SelectRows(
#"Changed Type",
each [Item] = "Alpha" or [Item] = "Charlie"
)
There are three important pieces here:
Table.SelectRowsreturns the rows that meet our condition.#"Changed Type"identifies the previous step containing the table.eachapplies the condition to each row.
The condition produces a true or false result. If it returns true, Power Query keeps the row. If it returns false, Power Query removes it.
We can see the principle by replacing the condition with each true, which returns every row, or each false, which returns no rows.
So the key is to replace the hard-coded comparison with a function that checks whether an item belongs to our list.
Convert the filter query to a list
Select the FilterList query, then select its column and choose Transform > Convert to List. Alternatively, right-click the column header and select Drill Down.
The query now returns a list rather than a table. Its icon in the Queries pane changes to reflect that.
Back in the Data query, replace the hard-coded filter with:
= Table.SelectRows(
#"Changed Type",
each List.Contains(FilterList, [Item])
)
List.Contains checks whether the current row’s Item value appears in FilterList. A match returns true, so the row stays. No match returns false, so the row is removed.
With Alpha and Charlie in the list, the result contains only records for those two items.
Make the comparison case-insensitive
By default, this comparison is case-sensitive. Alpha and alpha are not treated as the same value.
List.Contains has an optional third argument called equationCriteria. We can use it to control the comparison. To ignore differences between uppercase and lowercase letters, use Comparer.OrdinalIgnoreCase:
= Table.SelectRows(
#"Changed Type",
each List.Contains(
FilterList,
[Item],
Comparer.OrdinalIgnoreCase
)
)
Comparison options can also address culture-specific text differences, but for a straightforward uppercase and lowercase match, this comparer does the job.
Change the filter without editing the query
Load the result back into Excel using Home > Close & Load. If the query is already connection-only, right-click it in the Queries & Connections pane, select Load To, and load it as a table on a new worksheet.
Now change the Excel filter list from Alpha and Charlie to Delta and Charlie. Select Data > Refresh All, and the result updates to include those items instead.
Add Alpha back into the list, refresh again, and the result includes Charlie, Alpha, and Delta. There’s no need to reopen the query or add another condition.
Keep the filter query as a table
What if we don’t want to convert FilterList into a list? We can leave it as a table and extract the column inside the formula:
= Table.SelectRows(
#"Changed Type",
each List.Contains(FilterList[Filter List], [Item])
)
Here, FilterList is the query name, while [Filter List] identifies the column to extract. Together, FilterList[Filter List] supplies the list that List.Contains needs.
Make sure the column name matches exactly, including spaces.
Exclude the values in the list
To turn an inclusion list into an exclusion list, add not before List.Contains:
= Table.SelectRows(
#"Changed Type",
each not List.Contains(FilterList[Filter List], [Item])
)
Now matching items are removed rather than retained. In our example, excluding Alpha, Charlie, and Delta leaves only Bravo records.
2. Use Merge Queries as a faster alternative
For a simple matching scenario, we don’t have to edit M code at all. We can use a merge transformation.
Keep FilterList as a table, then follow these steps:
- In the Data query, remove the existing filtered-rows step if you are replacing the previous method.
- Select Home > Merge Queries.
- Use Data as the first table and FilterList as the second.
- Select the Item column in Data.
- Select the Filter List column in FilterList.
- Change the join kind to Right Outer, then click OK.
- Remove the nested FilterList column added by the merge.
With the matching values used in this example, the remaining data rows contain the items in our filter list. Bravo is no longer included.
List.Contains or merge: which should we choose?
Speed can make a big difference. In my test using 100,000 rows filtered by two values:
- List.Contains: 18.2 seconds.
- Merge: 1.6 seconds.
That made the merge more than ten times faster in that test.
However, a merge is a column-matching operation. It’s a good fit when the filter is simply based on matching values in the available columns. List.Contains gives us more flexibility when we need to build a more complex true or false condition.
For simple matching, consider a merge. For more involved filtering logic, use List.Contains.
3. Filter columns using a list of column names
So far, we’ve filtered rows. But a list can also control which columns appear in the output.
Our Data query contains Date, Item, Model, Region, and Value. The ColumnList query contains Date, Item, Region, and Value. We want to return only those listed columns.
- In the Data query, select a few columns to keep.
- Select Home > Remove Columns > Remove Other Columns.
- In the formula bar, replace the fixed list of column names with the column from ColumnList.
The resulting formula is:
= Table.SelectColumns(
#"Changed Type",
ColumnList[Column List]
)
Table.SelectColumns takes the table and a list of columns to retain. Instead of supplying that list directly in the code, we’re supplying it from our Excel table.
The output now contains Date, Item, Region, and Value, leaving out Model.
The list also controls column order
Load the result into Excel, then replace Item with Model in the column list so it reads:
- Date
- Model
- Region
- Value
Refresh the output. Power Query returns those four columns in the same order as the list.
This means the list controls both column selection and the final layout.
I recommend placing this transformation near the end of the query. If a later step refers to a column that the list has removed, that step will cause an error. Keep the columns needed for your transformations until those transformations are complete, then select the final output columns.
4. Create a dynamic filter list from the data
An Excel table makes filter values easy to maintain, but sometimes we don’t want to maintain them manually at all.
Suppose we want every record belonging to the three models with the highest total Value. As the data changes, the top three models may change too.
We need to calculate the qualifying models first, then use that list to filter the original detailed data.
Calculate the top three models
- Duplicate the Data query and name the duplicate Dynamic.
- Remove the earlier example transformations, returning to the Changed Type step with all five original columns.
- Select the Model column and choose Home > Group By.
- Name the new column Total.
- Set the operation to Sum and the column to Value, then click OK.
- Sort Total in descending order using Z to A.
- Select Home > Keep Rows > Keep Top Rows, enter 3, and click OK.
- Select the Model column and choose Transform > Convert to List.
We now have a list containing the three models with the highest totals.
Filter the original rows using the calculated list
At this point, two applied steps give us everything we need:
- Changed Type: The detailed table before grouping.
- Model: The list of the top three models created by the drill-down step.
Click the fx button beside the formula bar to add a new step, then enter:
= Table.SelectRows(
#"Changed Type",
each List.Contains(Model, [Model])
)
The two uses of Model have different meanings:
Modelwithout brackets refers to the applied step containing our calculated list.[Model]in square brackets refers to the Model value in the current row of the detailed table.
Importantly, Table.SelectRows filters the earlier Changed Type table, not the grouped summary. That brings back the individual records for the qualifying models.
In our example, those models are Picasso, Rembrandt, and Picasso Pro. The result includes their detailed rows, rather than just three summary rows.
On refresh, Power Query recalculates the totals, finds the top three models, rebuilds the list, and filters the original data. The filter values are now completely dynamic.
Choose the approach that fits your output
These four methods solve slightly different problems. List.Contains provides flexible row filtering, while a merge offers a straightforward alternative for matching columns. Table.SelectColumns lets an Excel list control the output layout, and a calculated list lets the data determine its own filter values.
The common idea is simple: move the changing values out of the filter expression and into a list. Whether that list comes from an Excel table or an earlier query step, the result is a query that can adapt when you refresh.


