Power Query Filter Based on Two Columns
In this article
To filter a table in Power Query based on two columns, you add a custom column that combines the two values and filter on that combined column, or you merge the two columns and filter the result. The most reliable method is to create a custom column using a delimiter that cannot appear in your data, then filter that column with the values you want. This works in Excel and Power BI because both use the same Power Query engine. You need your data loaded into Power Query and at least two columns with values you want to match together.
What You'll Need
- Excel (Microsoft 365 or Excel 2019 and later) or Power BI Desktop with Power Query available.
- Your data loaded into Power Query (Data > From Table/Range in Excel, or Get Data in Power BI).
- Two columns you want to filter together, for example a Region column and a Product column.
- A clear idea of the exact value pairs you want to keep, such as "North" + "Widget" and "South" + "Gadget".
Step-by-Step
- Open your query in the Power Query Editor. In Excel, select a cell in your table and go to Data > From Table/Range. In Power BI, use Home > Transform data to open the editor.
- Check the data types of the two columns you want to use. Click the data type icon in each column header and set both to Text. If one column is a number, converting to Text prevents type mismatches when you combine values. Note that menu labels can differ slightly by version, device or region.
- Add a custom column. Go to Add Column > Custom Column. In the dialog, give the column a name such as "FilterKey".
- Enter a formula that joins the two columns with a delimiter. The pipe character is a good delimiter because it rarely appears in real data. If your data might contain the pipe, use a different character such as a tilde (~) or a double pipe (||).
- Click OK. A new column appears with combined values such as "North|Widget".
- Filter the new column. Click the filter arrow on the FilterKey column header. Clear the checkboxes for values you do not want, or use Text Filters > Equals to enter a specific pair. To keep multiple pairs, use Text Filters > Equals for one pair, then repeat for others, or use the checkbox list to select the pairs you need.
- If you have many value pairs to keep, a more scalable approach is to create a separate table listing the allowed pairs, then merge queries. Create a new query with two columns (the same two columns) and one row per allowed pair. Add a custom column to that table using the same delimiter formula. Then go to Home > Merge Queries and merge your main query with the allowed-pairs query on the FilterKey column. Expand only the key column from the merged table, then filter out nulls in the expanded column. This keeps only rows whose pair exists in your list.
- Remove the helper column if you no longer need it. Right-click the FilterKey column header and choose Remove. The filter remains applied to the rows.
- Close and load. In Excel, go to Home > Close & Load. In Power BI, go to Home > Close & Apply.
Common Mistakes
- Using a delimiter that appears in your data. If a value contains the pipe character, two different pairs can produce the same combined string. Choose a delimiter that does not occur in either column, or use a multi-character delimiter.
- Forgetting to set both columns to Text. A number column and a text column combined can produce unexpected results, and leading zeros may be lost.
- Filtering each column separately with AND logic. Filtering Region to "North" and Product to "Widget" keeps only rows where both are true, which is not the same as keeping specific pairs such as North+Widget and South+Gadget. Use the combined-column method for pair-level filtering.
- Case sensitivity. Power Query text comparisons are case-sensitive by default in many operations. If your data has "north" and "North", the combined keys will not match. Use Text.Proper or Text.Lower on both columns before combining if case varies.
- Trailing spaces. Values like "North " and "North" produce different keys. Trim both columns with Text.Trim before combining.
Tips
- Keep the helper column until you have confirmed the filter works, then remove it. If you remove it too early, you lose the ability to adjust the filter easily.
- For a list of many allowed pairs, the merge approach is easier to maintain than a long checkbox selection. You can edit the allowed-pairs table and refresh instead of rebuilding the filter.
- Document the delimiter you chose in a comment or a note in the query, so others understand the logic.
- If you need to filter on more than two columns, extend the same pattern with additional delimiters, such as [Col1] & "|" & [Col2] & "|" & [Col3].
Troubleshooting
- No rows returned after filtering: check that the combined values exactly match what you entered. Look for extra spaces, different case, or hidden characters. Use Text.Trim and Text.Lower to normalise.
- The filter arrow does not show the values you expect: the column may contain nulls or errors. Filter out nulls first, or replace errors before combining.
- Merge returns many more rows than expected: the allowed-pairs table may contain duplicate keys. Remove duplicates from that table before merging.
- Data type changes after refresh: if source columns change type, the combined column may break. Set data types explicitly and avoid relying on automatic detection.
- If the merge approach does not work, fall back to the custom column and checkbox filter method. Both are valid; choose the one that fits your data volume and maintenance needs.
Frequently Asked Questions
Can I filter on two columns without adding a helper column?
You can filter each column separately, but that applies AND logic across the whole table, not pair-level logic. To keep specific pairs, a helper column or a merge with an allowed-pairs table is the practical approach.
Does this work in both Excel and Power BI?
Yes. Both use the Power Query engine, so the steps are the same. Menu locations differ slightly between the two applications.
What delimiter should I use?
Choose a character or string that does not appear in either column. A pipe (|), tilde (~), or a multi-character sequence like "||" are common choices. Test with a small sample first.
How do I keep more than a few value pairs?
Create a separate table of allowed pairs, add the same combined key to both queries, and merge. Then expand and filter out nulls. This scales better than selecting many checkboxes.
Why do my combined values not match my filter list?
Check for case differences, leading or trailing spaces, and data type mismatches. Normalise both columns with Text.Trim and Text.Lower before combining.
Can I use this with more than two columns?
Yes. Extend the custom column formula with additional delimiters and columns, then filter on the combined result.