Smart Systems for Home

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

Power Query Table.AddFuzzyClusterColumn Guide

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

Table.AddFuzzyClusterColumn groups similar text values into a single canonical value, so you can clean messy categories like city names, product labels or company names without writing a long list of manual replacements. It does this by comparing each row against a set of example values, measuring similarity, and then assigning the closest match. You need Power Query in Excel or Power BI, a table with a text column, and at least one example value (or a small table of examples) that represents the correct spelling or grouping. The function is available in the Power Query M formula language and can be added through the graphical interface or by editing the M code directly.

What You'll Need

  • Excel (Microsoft 365 or a recent version) or Power BI Desktop with Power Query.
  • A data source loaded into Power Query (Excel table, CSV, database, etc.).
  • A text column containing values to cluster.
  • A list of example values or a small reference table that defines the correct groups. If you do not have one, you can create it in a blank query.
  • Basic familiarity with the Power Query Editor and the M formula bar.

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. The Power Query Editor opens.
  2. Check the column type. Select the column you want to cluster and confirm it is set to Text. If it is not, use Transform > Data Type > Text. Fuzzy clustering works on text, not numbers.
  3. Create a list of example values. You can type them directly into the formula, or create a small table in the worksheet and load it as a query. For example, if you are clustering city names, your examples might be "New York", "Los Angeles", "Chicago". Keep the list short but representative.
  4. Open the Advanced Editor or the formula bar. You can add the function by editing the M code. Go to Home > Advanced Editor to see the full query, or click the formula bar (fx) to edit a step. The function is called Table.AddFuzzyClusterColumn.
  5. Write the function call. The syntax is:
    Table.AddFuzzyClusterColumn(table, columnName, exampleValues, [options])
    Replace table with your previous step name, columnName with the name of your text column (in quotes), and exampleValues with a list of text values (e.g., {"New York", "Los Angeles", "Chicago"}). The optional fourth argument is a record of options such as Culture, Threshold, IgnoreCase, IgnoreSpace, SimilarityColumnName, and TransformationTable. For a first attempt, you can omit it.
  6. Run the step. Press Enter or click the checkmark. Power Query adds a new column containing the clustered value for each row. The original column remains unchanged.
  7. Review the results. Scroll through the new column. If some values are grouped incorrectly, adjust the example list or add options. For instance, set Threshold to a value between 0 and 1 (default is 0.8) to control how similar a value must be to be clustered. A higher threshold means stricter matching.
  8. Rename the new column if needed. Double-click the column header and type a clearer name, such as "City (Clustered)".
  9. Load the result. When satisfied, go to Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to load the cleaned data.

Note: Menu labels can differ slightly by version, device or region. The steps above are for the Power Query Editor in Excel and Power BI Desktop; the web version of Power Query has a similar but not identical interface.

Common Mistakes

  • Using a column that is not text. The function expects a text column. If your column contains numbers or mixed types, convert it to text first.
  • Passing example values as a single string. The third argument must be a list, not a text value. Use curly braces: {"A", "B"}.
  • Forgetting to include enough examples. If your example list is too short or missing key variants, clustering will be poor. Include at least one example per intended group.
  • Ignoring case and spaces. By default, the function may treat "New York" and "new york" as different. Use the IgnoreCase and IgnoreSpace options to handle these.
  • Assuming the original column is replaced. The function adds a new column; the original stays. You can remove the original later if you wish.
  • Not checking the similarity score. If you add SimilarityColumnName in the options, you get a numeric score per row. Use it to spot borderline matches.

Tips

  • Start with a small subset of data to test your example list and threshold before applying to the full dataset.
  • Use the TransformationTable option to provide a table of mappings (e.g., "NY" to "New York") that the function will apply before clustering.
  • If you need to cluster multiple columns, apply the function separately to each column.
  • Combine with Table.TransformColumns to clean other columns in the same step.
  • Document your example list and options in a comment or a separate query so you can revisit them.

Troubleshooting

If the function returns an error, check the column name spelling and ensure the column exists in the table. If the new column is empty or all values are the same, your example list may be too narrow or the threshold too low. Try adding more examples or lowering the threshold. If clustering is too aggressive (different values grouped together), raise the threshold or add more distinct examples. If performance is slow on large tables, consider filtering the data first or using a smaller example list. If you see unexpected results, use the SimilarityColumnName option to inspect scores and adjust accordingly. If the function is not recognized, ensure you are using a version of Power Query that supports it (it is available in Excel 2016 and later, and Power BI Desktop).

Frequently Asked Questions

What does Table.AddFuzzyClusterColumn do?

It adds a new column that contains a canonical value for each row, chosen from a list of example values based on fuzzy matching of the original text.

Can I use it without a list of example values?

No, the function requires a list of example values to cluster against. You can create the list manually or from another query.

How do I control how similar values must be?

Use the Threshold option in the fourth argument, a number between 0 and 1. The default is 0.8; higher values require closer matches.

Does it work on numbers?

No, it works on text. Convert numbers to text first if you need to cluster them, but be aware that numeric similarity may not behave as expected.

Can I cluster multiple columns at once?

No, the function operates on one column at a time. Apply it separately to each column you want to cluster.

Is the original column modified?

No, the function adds a new column and leaves the original unchanged. You can remove the original column afterward if you wish.