Smart Systems for Home

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

Power Query CompareFromCulture Function: How to Use It

· 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

The Power Query CompareFromCulture function compares two text values using culture-specific rules for sorting and case handling, ensuring accurate comparisons in multilingual environments. It requires no external tools or setup beyond access to Power Query in Excel or Power BI. This function is essential when comparing strings that include accented characters, regional spellings, or locale-sensitive case rules.

What You'll Need

  • Microsoft Excel 2016 or later, or Microsoft Power BI Desktop
  • A data source loaded into Power Query (e.g., Excel table, CSV, database)
  • Basic familiarity with Power Query Editor and M language syntax
  • At least two text columns or values to compare

Step-by-Step

  1. Open Excel or Power BI Desktop and load your data into Power Query Editor. Go to Data > Get Data > From Table/Range (in Excel) or Get Data > Combine Queries > Combine as New Query (in Power BI) if combining multiple sources.
  2. In the Power Query Editor, identify the two text columns you want to compare. For example, you might have a column named "CustomerName" and another named "AlternateName" that should match despite regional spelling differences.
  3. Click on the "Add Column" tab, then select "Custom Column" from the ribbon. This opens the Custom Column dialog box.
  4. In the "New column name" field, type a clear name such as "MatchResult". In the "Custom column formula" box, enter: CompareFromCulture([CustomerName], [AlternateName], true). The third parameter, true, enables case-insensitive comparison; use false for case-sensitive matching.
  5. Click OK. Power Query will generate a new column with true/false values indicating whether the two text values match under the current system culture.
  6. To change the culture used for comparison, wrap the CompareFromCulture function in a let statement with a culture identifier. For example: let culture = "fr-FR", result = CompareFromCulture([CustomerName], [AlternateName], true, culture) in result. This forces French culture rules for accented characters like "é" and "è".
  7. Use the Filter button on the new "MatchResult" column to show only rows where the result is true or false, depending on your goal — identifying mismatches or confirming matches.
  8. Click "Close & Load" to send the results back to Excel or Power BI. The comparison logic is preserved in the query and will re-run when you refresh data.

Common Mistakes

  • Forgetting the third parameter (case sensitivity) and getting unexpected results due to default behavior — always explicitly state true or false.
  • Using CompareFromCulture with non-text columns (e.g., numbers or dates), which causes a type error. Ensure both inputs are text using Text.From() if needed.
  • Assuming CompareFromCulture uses the local system culture automatically — it does, but if your data spans multiple regions, you must explicitly specify the culture identifier to avoid inconsistent comparisons.
  • Typing the function name incorrectly (e.g., CompareFromCulture vs. CompareFromCulture()). The function requires exactly two or three parameters; adding a fourth causes an error.
  • Using culture codes that don’t exist, such as "en-US" instead of "en-US" — all culture identifiers must be valid according to the .NET CultureInfo class.

Tips

  • Always test CompareFromCulture with known edge cases: "café" vs. "cafe", "Mueller" vs. "Müller", or "straße" vs. "strasse". These highlight how culture affects comparison.
  • If you're comparing names across multiple countries, create a lookup table mapping each record to its correct culture (e.g., "fr-FR" for French names) and use it in a column formula with Table.AddColumn.
  • Combine CompareFromCulture with Text.Clean() or Text.Trim() to remove hidden characters that can break comparisons even when text looks identical.
  • Use the "View Advanced Editor" to manually edit the M code if you need to nest CompareFromCulture inside other functions like List.Select or Table.SelectRows.
  • For reports, add a conditional column to label matches as "Exact", "Near", or "Mismatch" based on CompareFromCulture results — this improves readability for non-technical users.
  • Remember: CompareFromCulture does not perform fuzzy matching or phonetic similarity. It only applies cultural rules to exact string comparison. Use Levenshtein distance algorithms if you need approximate matching.

Troubleshooting

  • If you see "Expression.Error: The name 'CompareFromCulture' wasn't recognized", your version of Power Query may be outdated. Update Excel or Power BI Desktop to the latest version from Microsoft Store or official website.
  • If the result is always false, check that both columns contain text. Use the Transform > Data Type > Text option on each column before comparison.
  • If the comparison behaves inconsistently across machines, ensure both systems use the same regional settings. Go to Windows Settings > Time & Language > Region & Language and confirm the default language matches your intended culture.
  • If using a custom culture code and getting an error, verify it’s a valid .NET culture name using Microsoft’s official list (e.g., "de-DE", "es-ES", "ja-JP"). Avoid shorthand like "de" — use full codes.
  • If the function returns null, one of your input columns might contain null values. Wrap them in if statements: if [CustomerName] <> null and [AlternateName] <> null then CompareFromCulture([CustomerName], [AlternateName], true) else null.
  • Refresh the query after any change to culture settings. Power Query caches results and may not reflect new logic until refreshed.

Frequently Asked Questions

Can CompareFromCulture compare numbers or dates?

No. It only works with text inputs. Convert numbers or dates to text using Text.From() before comparison.

Does it work in Power Automate?

No. CompareFromCulture is exclusive to Power Query in Excel and Power BI Desktop. Power Automate uses different functions for string comparison.

Is CompareFromCulture case-sensitive by default?

No — the default behavior depends on the culture, but you must explicitly pass true or false as the third parameter. Never rely on defaults.

What cultures are supported?

All cultures supported by .NET Framework’s CultureInfo class are valid, including en-US, fr-FR, de-DE, ja-JP, ar-SA, and many others.

Can I compare more than two strings at once?

Not directly. You must compare pairs. To compare three values, create multiple custom columns or use List.Contains() with a list of strings.

Why does "Müller" not match "Mueller" even with German culture?

Because CompareFromCulture performs exact string comparison under cultural rules, not phonetic or transliteration rules. "ü" and "ue" are distinct characters in string comparison, even in German culture.