Smart Systems for Home

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

Power Query Comparer.OrdinalIgnoreCase Explained

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

Comparer.OrdinalIgnoreCase is a built-in comparer value in Power Query M that tells functions like Table.Distinct, Table.SelectRows, List.Contains, and List.Distinct to treat text as equal regardless of uppercase or lowercase letters, while still comparing characters by their ordinal (Unicode code point) value rather than by linguistic rules. In practice, that means "Apple" and "apple" are treated as the same value when you pass Comparer.OrdinalIgnoreCase as the comparer argument, and the function returns or removes rows accordingly. You do not install anything or enable a feature: the comparer is part of the M language and works in Power Query in Excel, Power BI Desktop, and the Power Query Online editor. What you do need is a query that already contains text columns you want to compare, and a basic understanding of where the optional comparer argument sits in the function you are calling.

What You'll Need

  • Power Query available in Excel (Data > Get Data), Power BI Desktop (Home > Transform data), or the Power Query Online editor.
  • A query loaded with at least one text column, or a small table you can paste in to experiment with.
  • Access to the formula bar or the Advanced Editor so you can type the comparer argument directly, because most ribbon buttons do not expose a comparer choice.
  • Familiarity with the function you plan to use, since the comparer is an optional argument and its position depends on the function.

Step-by-Step

  1. Open the query you want to work on. In Excel, go to Data > Get Data > Launch Power Query Editor. In Power BI Desktop, go to Home > Transform data. In Power Query Online, open your dataflow or query and select the query. Menu labels can differ slightly by version and region, but the editor itself is the same.
  2. Confirm the column is text. Select the column header and check the icon or the data type shown in the ribbon. If the column is Any or a number type, comparisons will not behave the way you expect. Use Transform > Data Type > Text to convert it first. This matters because Comparer.OrdinalIgnoreCase only affects text values.
  3. Decide which function needs the comparer. Common choices are Table.Distinct (remove duplicate rows), Table.SelectRows (filter rows), List.Contains (check whether a list contains a value), List.Distinct (deduplicate a list), and Text.Contains when used inside a custom column. Each of these accepts a comparer as an optional argument, but the position differs, so check the function's signature before typing.
  4. Open the Advanced Editor or the formula bar. In the Power Query Editor, go to Home > Advanced Editor to edit the whole query, or select a step and use the formula bar (View > Formula Bar if it is hidden). The Advanced Editor shows the full M code, which is the clearest place to add the comparer.
  5. Add the comparer argument in the correct position. For Table.Distinct, the syntax is Table.Distinct(table as table, optional equationCriteria as any). Pass Comparer.OrdinalIgnoreCase as the second argument, for example: Table.Distinct(Source, Comparer.OrdinalIgnoreCase). For List.Contains, the signature is List.Contains(list as list, value as any, optional equationCriteria as any), so the comparer goes third: List.Contains(MyList, "apple", Comparer.OrdinalIgnoreCase).
  6. Understand what the comparer returns. A comparer is a function that takes two values and returns a number: 0 when they are equal, a negative number when the first is less than the second, and a positive number when the first is greater. Comparer.OrdinalIgnoreCase returns 0 for "Apple" and "apple", which is why the surrounding function treats them as equal. You can test this directly by adding a step such as Comparer.OrdinalIgnoreCase("Apple", "apple") and confirming the result is 0.
  7. Apply the change and check the result. Select Done in the Advanced Editor or press Enter in the formula bar. Inspect the output table or list. If you used Table.Distinct, you should see only one row per case-insensitive value. If you used List.Contains, the step should now return true for values that differ only in case.
  8. Rename the step for clarity. Right-click the step in the Applied Steps pane and choose Rename, or edit the step name in the Advanced Editor. Names like "DistinctIgnoreCase" make it obvious later why rows disappeared, which matters when someone else maintains the query.
  9. Load or close and apply. In Excel, use Home > Close & Load to send the result to a worksheet or the data model. In Power BI Desktop, use Home > Close & Apply. In Power Query Online, save the query. The comparer logic is stored in the query definition, so it persists on refresh.

Common Mistakes

  • Putting the comparer in the wrong argument position. Each function has its own signature. Table.Distinct takes the comparer second, List.Contains takes it third, and Table.SelectRows does not take it as a direct argument at all. Check the function signature before typing.
  • Expecting the comparer to fix data type problems. If a column is typed as a number or as Any, Comparer.OrdinalIgnoreCase will not make text comparisons work. Convert the column to Text first.
  • Assuming OrdinalIgnoreCase matches culture-aware rules. It compares Unicode code points, not language-specific collation. Characters that look similar but are different code points, such as accented letters, will not be treated as equal. That is by design, but it surprises people who expect "café" and "cafe" to match.
  • Using it where a culture comparer is needed. If you need language-aware sorting or comparison, Comparer.OrdinalIgnoreCase is the wrong tool. Use Comparer.FromCulture with the appropriate culture and case-sensitivity setting instead.
  • Forgetting that Table.Distinct with a comparer may keep an arbitrary row. When duplicates are removed, the row that survives is not guaranteed to be the first one in the original order. If you need a specific row kept, sort first or use a different approach such as grouping.

Tips

  • Test the comparer in isolation before wiring it into a big query. A step like Comparer.OrdinalIgnoreCase("A", "a") returning 0 confirms the behaviour quickly.
  • Use the formula bar rather than the Advanced Editor for small edits; it is less error-prone and shows the current step's code only.
  • Combine the comparer with Table.Buffer when the source is slow or remote, so the comparison runs against an in-memory table rather than re-querying the source.
  • Keep a comment or a clear step name explaining why case-insensitive comparison was chosen, especially if the source data is expected to be consistently cased.
  • Remember that Comparer.OrdinalIgnoreCase is case-insensitive but still ordinal, so it is fast and predictable. That makes it a good default for identifiers, codes, and email addresses where case should not matter.

Troubleshooting

  • The query errors with "We cannot convert a value of type Function to type Text". You likely passed the comparer where a text value was expected, or placed it in the wrong argument slot. Recheck the function signature and move the comparer to the optional equationCriteria position.
  • Duplicates remain after Table.Distinct. Confirm the column is Text, confirm the comparer is actually in the step, and check for leading or trailing spaces. Comparer.OrdinalIgnoreCase ignores case but not whitespace, so trim the column first with Transform > Format > Trim.
  • Values that look identical are not matched. They may differ by invisible characters, non-breaking spaces, or different Unicode code points. Use Text.Clean and Text.Trim, and inspect the values with Text.ToList to see the actual characters.
  • The step works in one tool but not another. Comparer functions are part of the M language and behave the same across Excel, Power BI Desktop, and Power Query Online, but the editor's error messages and formula bar behaviour differ. If a step fails, open the Advanced Editor to see the exact code being submitted.
  • Nothing changes after editing. Make sure you clicked Done in the Advanced Editor or pressed Enter in the formula bar. If the step still looks unchanged, check that you edited the correct step and not a later one that overrides it.

Frequently Asked Questions

Is Comparer.OrdinalIgnoreCase available in Excel Power Query?

Yes. It is part of the M language and works in Power Query in Excel, Power BI Desktop, and Power Query Online. No add-in or setting is required.

Does it ignore accents as well as case?

No. It ignores case only. Accented and unaccented characters are different code points, so "café" and "cafe" are not treated as equal. For culture-aware comparison, use Comparer.FromCulture.

Can I use it with Table.SelectRows?

Not as a direct argument.

What does the comparer actually return?

It returns a number: 0 when the two values are equal ignoring case, a negative number when the first sorts before the second, and a positive number when it sorts after. Functions use that number to decide equality.

Why did Table.Distinct keep a different row than I expected?

When duplicates are removed, the surviving row is not guaranteed to be the first in source order. Sort the table first if you need a specific row kept, or use grouping to control which values are retained.

Is it faster than Comparer.FromCulture?

Ordinal comparison is generally simpler and more predictable than culture-aware comparison, but speed depends on your data and environment. For identifiers and codes, OrdinalIgnoreCase is usually the appropriate choice.