Power Query does not have a native "wildcard" character (like the asterisk * or question mark ?) in its standard filter menus, but you can achieve the same result by using Text functions like Text.Contains, Text.StartsWith, and Text.EndsWith in the formula bar or through the Filter menu's text filters. This allows you to isolate rows where a column contains a specific string regardless of what comes before or after it.
What You'll Need
- Microsoft Excel or Power BI Desktop.
- A dataset loaded into the Power Query Editor (Get Data).
- Basic familiarity with the Power Query interface (the ribbon and the formula bar).
Step-by-Step
Depending on whether you want a simple "contains" filter or a more complex pattern, use one of the following three methods. Note that menu labels may vary slightly depending on your version of Excel or Power BI.
Method 1: Using the Built-in Text Filters (The Easy Way)
- Open the Power Query Editor by selecting Data > Get Data > Launch Power Query Editor.
- Locate the column you wish to filter using a wildcard-style pattern.
- Click the filter arrow (drop-down) in the column header.
- Navigate to Text Filters. Here you will see options that act as wildcards:
- Select Contains... if you want to find a word anywhere in the cell (equivalent to
*text*). - Select Begins With... if you want to find a word only at the start (equivalent to
text*). - Select Ends With... if you want to find a word only at the end (equivalent to
*text). - In the dialog box that appears, type the specific text you are looking for and click OK.
Method 2: Customizing the Formula Bar for Dynamic Wildcards
Sometimes the built-in filters are too rigid. You can edit the M code in the formula bar to make the filter more flexible.
- Apply a basic "Contains" filter as described in Method 1. This creates a step in the Applied Steps pane.
- Look at the formula bar at the top. You will see a function that looks like this:
= Table.SelectRows(#"Previous Step", each Text.Contains([ColumnName], "yourtext")). - To make this case-insensitive (since Power Query is case-sensitive by default), add
Comparer.OrdinalIgnoreCaseas a third argument. - Modify the code to:
= Table.SelectRows(#"Previous Step", each Text.Contains([ColumnName], "yourtext", Comparer.OrdinalIgnoreCase)). - Press Enter to apply the change.
Method 3: Using a Custom Column for Complex Pattern Matching
If you need to check for multiple different "wildcard" patterns at once, a custom column is the most reliable approach.
- Go to the Add Column tab on the ribbon and select Custom Column.
- Give your column a name, such as "FilterCheck".
- In the custom column formula box, use an
ifstatement combined withText.Contains. For example, to find rows containing either "North" or "South":if Text.Contains([Region], "North") or Text.Contains([Region], "South") then "Keep" else "Remove". - Click OK.
- Click the filter arrow on your new "FilterCheck" column and uncheck "Remove".
- Right-click the "FilterCheck" column and select Remove to clean up your data, leaving only the filtered rows.
Common Mistakes
The most frequent error when attempting wildcard filtering in Power Query is ignoring case sensitivity. In standard Excel cells, "Apple" and "apple" are often treated the same. In Power Query, they are completely different. If you filter for "Apple" and your data contains "apple", those rows will be deleted. Always check your casing or use the Comparer.OrdinalIgnoreCase argument in the M code.
Another common mistake is trying to use * or % symbols directly inside the "Contains" filter box. Power Query does not interpret these as wildcards; it treats them as literal characters. If you type *Sales* into the filter box, Power Query will look for cells that actually contain an asterisk character, not any text surrounding the word "Sales".
Users also frequently forget to check for null values. If a column contains nulls, functions like Text.Contains may return an error for those specific rows, which can cause the entire filter step to fail or result in the loss of data you didn't intend to remove. To avoid this, ensure you replace nulls with empty strings or add a null check to your custom formula (e.g., if [Column] <> null and Text.Contains([Column], "text") then...).
Tips
For those handling massive datasets, avoid using too many Text.Contains filters in a row. Each filter step creates a new table transformation. If you have five different wildcard requirements, it is significantly more efficient to write one single Table.SelectRows step with multiple or conditions than to have five separate filtered steps in your Applied Steps list.
If you find yourself constantly changing the "wildcard" text you are searching for, create a Parameter. Go to Home > Manage Parameters > New Parameter. Name it "SearchTerm". Then, in your filter formula, replace the hardcoded text "yourtext" with the parameter name SearchTerm. Now, you can change the filter criteria from the main Excel/Power BI screen without opening the Power Query Editor.
When dealing with complex patterns (like verifying if a string follows a specific digit-letter-digit format), Power Query's basic text functions aren't enough. While Power Query doesn't natively support Regular Expressions (Regex) in the UI, you can use Text.Select to strip out everything except numbers or letters to see if the remaining "skeleton" of the data matches your pattern.
Troubleshooting
The filter is returning zero results, but I know the data is there.
First, check the capitalization. As mentioned, Power Query is case-sensitive. Second, check for leading or trailing spaces in your data. A cell that looks like " Apple" (with a space) will not be caught by a "Begins With: Apple" filter. To fix this, right-click the column and select Transform > Trim before applying your filter.
This happens because the
Text.Contains function cannot process a null cell. To solve this, go to the Transform tab, select Replace Values, and replace null with an empty string (leave the "Replace With" box completely blank). Now the text functions can run across every row without crashing.
The filter is too slow and freezing my computer.This is often due to "Query Folding" being broken. When you use complex custom M code, Power Query may stop asking the database (like SQL) to do the filtering and instead download the entire dataset to your RAM to filter it locally. To minimize this, try to use the built-in UI filters (Method 1) as much as possible, as these are more likely to be "folded" back to the server.
Frequently Asked Questions
Can I use a question mark as a single-character wildcard?
No, Power Query does not support the ? symbol as a single-character wildcard. To achieve this, you would need to use Text.Length to verify the string is the correct size and Text.Middle to check specific character positions.
Is there a way to do a "Does Not Contain" filter?
Yes. In the Text Filters menu, select Does Not Contain.... Alternatively, in the M code, you can wrap your function in not, such as each not Text.Contains([Column], "text").
How do I filter for multiple different wildcard terms at once?
The easiest way is to use the Advanced radio button in the Text Filter dialog box. This allows you to add multiple clauses using "And" or "Or" logic (e.g., Column contains "Red" OR Column contains "Blue").
Does Power Query support Regex for advanced wildcards?
Not natively in the user interface. To use Regular Expressions, you would need to invoke an R or Python script within Power Query, which requires those languages to be installed on your machine and configured in the options.
Can I use a wildcard to filter file names when importing a folder?
Yes. When you use Get Data > From Folder, Power Query lists all files. You can then use the Text.Contains filter on the "Name" column to only load files that match a certain pattern, such as all files containing the word "Invoice".