Smart Systems for Home

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

Power Query: Filter on Multiple Columns

· 7 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

You can filter on multiple columns in Power Query by applying a filter to each column in turn, or by using a single filter with multiple conditions on the same column. The key is that Power Query applies filters sequentially, so each filter narrows the data further. If you need OR logic across different columns, you will need to use a custom column or merge queries instead, because the standard filter dropdowns only combine conditions with AND. This guide walks you through the practical steps for both approaches, using the Power Query Editor in Excel and Power BI, which share the same interface. Menu labels can differ slightly by version, device or region, but the core steps are the same.

What You'll Need

  • Excel 2016 or later, or Power BI Desktop, with the Power Query Editor available. In Excel, go to the Data tab and click "Get Data" or "From Table/Range". In Power BI, click "Transform Data" to open the editor.
  • A dataset loaded into Power Query with at least two columns you want to filter.
  • Basic familiarity with the Power Query Editor interface: the Queries pane on the left, the data preview in the middle, and the Applied Steps list on the right.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Home > Transform Data to open the Power Query Editor with your existing query. If you are starting from a blank query, use Home > New Source and pick your data source.
  2. Apply the first filter. Click the filter arrow on the first column you want to filter (for example, "Region"). Uncheck "(Select All)" and tick only the values you want to keep, then click OK. Alternatively, use Text Filters or Number Filters for conditions like "begins with" or "greater than". This adds a step to the Applied Steps list.
  3. Apply the second filter. Click the filter arrow on the second column (for example, "Product Category") and select the values you want. Power Query automatically combines this with the first filter using AND logic: rows must match both filters to remain. You will see a second step added to Applied Steps.
  4. Repeat for additional columns. Continue filtering each column as needed. Each filter narrows the dataset further. You can apply as many column filters as you like, but keep an eye on the row count in the status bar to ensure you are not filtering out too much data.
  5. Review and adjust the Applied Steps. If you need to change a filter, click the gear icon next to that step in the Applied Steps list. This reopens the filter dialog so you can modify the condition without starting over. You can also delete a step by clicking the X to its left, but be aware that subsequent steps may break if they depend on the removed step.
  6. For OR logic across columns, use a custom column. If you need rows where either Column A equals X OR Column B equals Y, the standard filters cannot do this directly. Go to Add Column > Custom Column and write a formula such as [Region] = "North" or [Category] = "Electronics". This creates a true/false column. Then filter that new column to keep only "true" values. This approach works for any combination of OR conditions.
  7. Alternatively, merge queries for OR logic. If you have two separate queries that each filter on different columns and you want the union of results, use Home > Append Queries as New. This combines the rows from both queries, effectively giving you OR logic across the entire dataset. Be careful with duplicates; you may need to remove them afterward.
  8. Close and load. Once your filters are set, go to Home > Close & Load (in Excel) or Home > Close & Apply (in Power BI) to apply the changes and load the filtered data into your worksheet or data model.

Common Mistakes

  • Assuming filters combine with OR. The filter dropdowns combine conditions with AND. If you select "North" in Region and "Electronics" in Category, you get only rows that are both North and Electronics. For OR, use a custom column or append queries.
  • Filtering on a column that has been removed or renamed. If you delete a step that created a column, later filters on that column will fail. Check the Applied Steps order and ensure filters reference existing columns.
  • Forgetting that filters are case-sensitive in some contexts. Text filters like "equals" may be case-sensitive depending on your data source and settings. Use "Text.Contains" with the Comparer.OrdinalIgnoreCase option in a custom column if you need case-insensitive matching.
  • Applying filters to the wrong query. If you have multiple queries, make sure you are editing the correct one. The Queries pane highlights the active query.
  • Over-filtering and losing data. Always check the row count after each filter. If the count drops to zero, you may have conflicting conditions (e.g., Region = North AND Region = South).

Tips

  • Use the "Filter Rows" dialog (right-click a column header > Text Filters > Custom Filter) to build more complex conditions with multiple criteria on the same column, such as "begins with A" AND "ends with Z".
  • Name your steps descriptively. Double-click a step in the Applied Steps list to rename it, making your query easier to understand and maintain.
  • If you frequently filter on the same combination of columns, consider creating a custom function or using parameters to make the query reusable.
  • Use the "Remove Duplicates" feature after appending queries to avoid duplicate rows when combining OR logic.
  • Keep the number of applied steps manageable. Too many steps can slow down refresh times, especially with large datasets.

Troubleshooting

  • Filter option is greyed out: This can happen if the column is of a complex type (e.g., a table or record) or if the query is not in a loadable state. Check the column data type and ensure it is a simple type like text, number, or date.
  • Filtered data does not refresh correctly: If your data source changes, filters may need to be reapplied. Go to Data > Refresh All (Excel) or Home > Refresh (Power BI). If the filter references a value that no longer exists, it may return zero rows. Edit the filter step to update the criteria.
  • Error: "We couldn't apply the filter" or similar: This often indicates a data type mismatch. For example, filtering a number column with a text value. Check the column data type and convert it if necessary using the Transform tab.
  • Custom column formula errors: Ensure column names are enclosed in square brackets and match exactly, including spaces. Use the formula bar to debug. If the formula is too complex, break it into multiple custom columns.
  • Performance issues with many filters: If the query is slow, consider filtering at the source (e.g., in the database query) rather than in Power Query. Alternatively, remove unnecessary columns before filtering to reduce data volume.

Frequently Asked Questions

Can I filter on multiple columns with OR logic using the standard filter dropdowns?

No, the standard filter dropdowns combine conditions with AND logic. For OR logic, you need to create a custom column with an OR formula or append two queries.

How do I filter a column to exclude multiple values?

In the filter dropdown, uncheck the values you want to exclude, or use Text Filters > Does Not Equal and enter the value. For multiple exclusions, you can use a custom filter with "does not equal" for each value, but the dialog only allows one condition per filter. Alternatively, create a custom column that checks if the value is in a list and filter on that.

What is the difference between filtering in Power Query and filtering in the worksheet?

Power Query filters are applied during data transformation and affect the data that is loaded. Worksheet filters are applied after loading and only affect the display. Power Query filters are better for reducing data size and improving performance.

Can I use wildcards in Power Query filters?

Yes, text filters support wildcards like * (any number of characters) and ? (single character). For example, "begins with A*" will match any text starting with A.

How do I filter on a column that contains null values?

In the filter dropdown, null values appear as "(null)". You can check or uncheck them like any other value. To filter out nulls, uncheck "(null)". To keep only nulls, uncheck all other values.

Can I apply a filter based on a parameter?

Yes, you can create a parameter and use it in a custom column or in the filter dialog by selecting "Advanced" and using the parameter. This is useful for dynamic filtering.