Power Query Fuzzy Matching: Guide to Joining Messy Data
In this article
Power Query fuzzy matching allows you to merge two tables based on approximate matches rather than exact matches. This is essential when dealing with "dirty" data, such as lists where a company name might be written as "Microsoft Corp" in one table and "Microsoft Corporation" in another. By using fuzzy logic, Power Query calculates the similarity between two strings of text and joins them if they meet a specific similarity threshold, effectively bypassing typos, casing differences, and minor naming variations.
What You'll Need
- Microsoft Excel (with Power Query installed) or Power BI Desktop.
- Two separate tables or datasets that share a common column (e.g., Customer Name, Product ID, or Vendor).
- The common columns must be formatted as Text data types for the fuzzy logic to function correctly.
Step-by-Step
- Load Your Data: Open your workbook or Power BI file. Go to the Data tab (Excel) or Home tab (Power BI) and select Get Data to bring your two tables into the Power Query Editor. Ensure both tables are loaded as queries.
- Initiate the Merge: In the Power Query Editor window, select your primary table. On the Home tab, click the Merge Queries dropdown. You can choose "Merge Queries" to add columns to the existing table or "Merge Queries as New" to create a third, combined table.
- Select Matching Columns: In the Merge window, select the first table in the top dropdown and the second table in the bottom dropdown. Click on the column in each table that contains the text you want to match (for example, "Client Name" in Table A and "Customer" in Table B). The columns will be highlighted in grey.
- Enable Fuzzy Matching: Look for the checkbox labeled "Use fuzzy matching to perform the merge" at the bottom of the Merge window. Check this box. This unlocks the "Fuzzy matching options" expander.
- Configure Similarity Threshold: Click the "Fuzzy matching options" arrow to reveal advanced settings. The most critical setting is the "Similarity threshold." This is a value between 0.00 and 1.00.
- A value of 1.00 requires an exact match.
- A value of 0.00 matches everything.
- A standard starting point is 0.80. If you are getting too many wrong matches, increase the number (e.g., to 0.90). If you are missing obvious matches, decrease the number (e.g., to 0.70).
- Ignore Case and Whitespace: Ensure the "Ignore case" option is checked. This prevents the system from treating "Apple" and "apple" as different entities. While not always visible in every version, Power Query generally handles leading and trailing whitespace automatically during fuzzy operations, but it is best practice to trim your columns beforehand.
- Apply a Transformation Table (Optional): If you have known aliases (e.g., "IBM" should always match "International Business Machines"), you can create a separate two-column table mapping the "From" value to the "To" value. In the Merge options, select this table in the "Transformation table" dropdown. This forces specific matches regardless of the similarity threshold.
- Execute and Expand: Click OK. You will now see a new column in your primary table containing "Table" objects. Click the small double-arrow icon in the header of this new column to expand it and select which columns from the second table you wish to display.
- Verify and Load: Scan the results for false positives. Once satisfied, click Close & Apply to load the cleaned, merged data back into your spreadsheet or model.
Common Mistakes
One of the most frequent errors is setting the similarity threshold too low. While it may seem helpful to catch every possible match, a threshold of 0.50 or 0.60 often leads to "false positives," where completely different words are joined simply because they share a few letters. For example, "Apple" might match "Apply" if the threshold is too permissive.
Another common mistake is attempting fuzzy matching on numeric columns. Fuzzy matching is designed for text strings. If you are trying to match IDs that have slight variations (like a leading zero missing), it is better to convert those columns to text first or use a custom column to standardize the length of the IDs before merging.
Users also frequently forget to "Trim" and "Clean" their data before starting. While fuzzy matching handles some noise, invisible characters (like non-breaking spaces from web imports) can sometimes skew the similarity score. Using the Transform > Format > Trim and Clean functions on your text columns before the merge ensures the algorithm is looking at the actual characters.
Tips
To optimize performance, always filter out nulls or empty rows from your matching columns before performing the merge. Fuzzy matching is computationally expensive; if you are merging tables with tens of thousands of rows, the process can slow down significantly. Reducing the dataset to only the necessary rows speeds up the calculation.
When using a Transformation Table, keep it simple. Only include the most problematic pairs that the algorithm consistently misses. Overloading a transformation table with thousands of entries can sometimes lead to unexpected results if the mapping is not one-to-one.
If you are unsure about the correct threshold, create a small sample of your data (100 rows) and test different values (0.7, 0.8, 0.9). Note which value captures the most correct matches without introducing errors, then apply that specific value to the full dataset.
Troubleshooting
If the merge is taking an extremely long time or causing the application to freeze, the first step is to check the size of your tables. If you have very large datasets, try to perform a standard "Exact Match" merge first to clear out the easy wins, then perform a fuzzy match only on the rows that didn't find a partner.
If you are seeing no matches at all despite the names looking similar, check the data types. If one column is "General" and the other is "Text," Power Query may struggle. Explicitly set both columns to "Text" using the data type icon in the column header.
If the fuzzy match is producing incorrect pairs (false positives), increase your similarity threshold in increments of 0.05. For instance, move from 0.80 to 0.85. If the problem persists, check for common words that might be triggering the match, such as "Inc" or "Ltd." You may need to use the "Replace Values" feature to remove these common suffixes from both tables before merging, as they can artificially inflate the similarity score of two unrelated companies.
Frequently Asked Questions
Does fuzzy matching change my original data?
No, Power Query is non-destructive. It creates a new merged table or adds columns to an existing query without altering the source files.
Can I use fuzzy matching for numbers?
Fuzzy matching is intended for text. For numbers, you should use standard joins or create a calculated column to group numbers into ranges (bins) to achieve a similar effect.
Is there a limit to how many tables I can fuzzy match?
You can only merge two tables at a time. If you have three or more tables, you must perform the fuzzy merge on the first two, and then merge the resulting table with the third one.
How does the similarity threshold actually work?
It uses the Jaccard Index or similar string-distance algorithms to calculate how many characters and sequences are shared between two strings relative to the total length of the strings.
Can I use fuzzy matching in standard Excel formulas?
No, fuzzy matching is a feature of Power Query (Get & Transform). Standard formulas like VLOOKUP or XLOOKUP require exact matches or wildcards, which are not as powerful as fuzzy logic.
What is the difference between a transformation table and a fuzzy match?
A fuzzy match is a probabilistic guess based on similarity; a transformation table is a hard rule that tells Power Query exactly which two different strings should be treated as identical.