To add a custom filter in Power Query, click the drop-down arrow in the column header, select Text Filters, Number Filters, or Date Filters, and choose a specific condition (such as "Begins With" or "Greater Than"). For more complex logic, select Custom Filter to combine multiple rules using AND/OR logic. This process allows you to remove unnecessary rows from your dataset before loading it into your report, which improves performance and ensures data accuracy.

Custom filtering is essential when simple checkboxes aren't enough. While a standard filter allows you to uncheck a few items, a custom filter creates a rule. For example, instead of manually unchecking 500 different dates, you can set a rule to "keep all dates after January 1st." This rule remains active even when your data refreshes and new rows are added.

What You'll Need

  • A dataset loaded into the Power Query Editor (available in Excel or Power BI).
  • A clear understanding of the criteria you want to filter by (e.g., a specific date range or a keyword).
  • Basic knowledge of whether your column is formatted as Text, Whole Number, Decimal, or Date, as the filter options change based on the data type.

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data from the Home ribbon.
  2. Select the Target Column: Locate the column you wish to filter. Click the small drop-down arrow icon located on the right side of the column header. (Note: Menu labels may differ slightly depending on your software version or region).
  3. Choose the Filter Category: Depending on the data type of your column, you will see different options:
    • Text Filters: Used for strings (e.g., Contains, Does Not Equal, Starts With).
    • Number Filters: Used for numeric values (e.g., Between, Greater Than, Less Than).
    • Date Filters: Used for calendar dates (e.g., In the Previous Month, After, Year-to-Date).
    Hover over the appropriate category to reveal the specific rules.
  4. Apply a Simple Custom Rule: Select a rule from the list (for example, Contains...). A dialog box will appear. Type the value you are looking for into the text box and click OK.
  5. Apply Complex Logic (Advanced Custom Filter): If you need more than one condition, select Custom Filter... at the bottom of the filter category menu.
    • In the dialog box, set your first condition (e.g., "is greater than 100").
    • Select either And (both conditions must be true) or Or (either condition can be true).
    • Set your second condition (e.g., "is less than 500").
    • Click OK.
  6. Verify the Applied Step: Look at the Applied Steps pane on the right side of the screen. You will see a new step labeled "Filtered Rows." You can click the gear icon next to this step at any time to modify your filter criteria.
  7. Load the Data: Once the data is filtered to your satisfaction, click Close & Apply (Power BI) or Close & Load (Excel) to bring the filtered data into your worksheet or model.

Common Mistakes

  • Ignoring Case Sensitivity: By default, Power Query is case-sensitive. If you filter for "Apple" but the data contains "apple," those rows will be filtered out. To fix this, right-click the column and select Transform > lowercase before applying the filter.
  • Wrong Data Types: Trying to apply a "Number Filter" to a column formatted as "Text" will result in the number filters being missing from the menu. Always check the icon to the left of the column header (e.g., 1.2 for decimal, ABC for text) before filtering.
  • Filtering Too Early: If you filter data before performing a necessary merge or join, you might accidentally remove rows that were needed for the relationship. Generally, filter as late as possible, but as early as necessary for performance.
  • Hard-coding Values: Using a specific date (like "1/1/2023") in a filter makes the query static. If you want the filter to update automatically every year, you will need to use a dynamic M-code function.

Tips

  • Use the Formula Bar: If you are comfortable with M-code, you can edit the filter directly in the formula bar at the top. This allows you to change "and" to "or" or tweak values without reopening the dialog box.
  • Filter by Example: If you aren't sure which rule to use, use the "Add Column From Examples" feature to create a True/False column based on your needs, then filter that column for "True."
  • Combine Filters: You can apply multiple filters across different columns. Power Query will stack these in the Applied Steps pane, effectively creating a multi-layered "And" filter.

Troubleshooting

If your filter is not working as expected, try these steps in order:

  1. Check for Trailing Spaces: Often, data imported from CSVs or web sources contains hidden spaces (e.g., "Active " instead of "Active"). Right-click the column and select Transform > Trim to remove leading and trailing whitespace, then re-apply the filter.
  2. Verify Data Types: Ensure the column is set to the correct type. If a number column is set to "Any," the numeric filters may behave unpredictably. Change the type to "Whole Number" or "Decimal" via the column header icon.
  3. Review the Applied Steps: If data is missing that should be there, check the Applied Steps pane. You may have an earlier filter step that is removing the data before it even reaches your custom filter.
  4. Refresh the Preview: Sometimes the Power Query preview does not update instantly. Click Refresh Preview in the Home tab to ensure you are seeing the most current state of the data.

Frequently Asked Questions

Can I create a filter that changes based on a cell value in Excel?

Yes, but it requires creating a named range for that cell and then referencing that name in the Power Query M-code using a custom function. This is not possible through the standard filter menu alone.

Does filtering in Power Query delete the original data?

No. Power Query is a non-destructive transformation tool. It creates a set of instructions to filter the data during the load process; the original source file remains untouched.

What is the difference between a basic filter and a custom filter?

A basic filter (checking/unchecking boxes) is a static list of existing values. A custom filter is a rule-based approach that applies to any value that meets the criteria, including new data added to the source later.

How do I remove a filter I already applied?

Go to the Applied Steps pane on the right side of the editor and click the X icon next to the "Filtered Rows" step. This will immediately restore all previously filtered data.

Can I filter for multiple keywords at once?

Yes. Use the Custom Filter option and use the Or operator. For example, set the rule to "Column contains 'Red'" OR "Column contains 'Blue'."