Comparer.Equals

Comparer

Returns a comparer function that tests equality using the given base comparer.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Comparer.Equals(comparer as function) as function

Parameters

NameTypeRequiredDescription
comparerfunctionYesA comparer function (such as Comparer.Ordinal or Comparer.OrdinalIgnoreCase) that defines the equality rules.

Return Value

functionA function that accepts two values and returns true if they are considered equal by the given comparer, false otherwise.

Remarks

Comparer.Equals wraps a base comparer function and returns a new binary predicate of the form (x, y) => logical. The returned function returns true when the comparer considers x and y equal (i.e., the comparer returns 0), and false otherwise. It is not meant to be called directly as a standalone comparison — its purpose is to produce a reusable equality function that can be passed to other functions.

A comparer function in M has the signature (x, y) => number and returns a negative number when x < y, zero when x = y, and a positive number when x > y. Comparer.Equals extracts only the equality case from this ordering contract.

Power Query is case-sensitive by default, so plain = comparisons treat "hello" and "HELLO" as different values. Comparer.Equals(Comparer.OrdinalIgnoreCase) is the standard way to perform case-insensitive equality testing. You should always specify the comparer explicitly rather than relying on locale defaults — use Comparer.OrdinalIgnoreCase for case-insensitive ASCII/Latin comparisons, or Comparer.FromCulture("en-US", true) when culture-aware folding is required.

The returned equality function is accepted by List.Contains, List.Distinct, List.Intersect, and List.Difference as their optional comparer parameter. For functions that accept a comparer directly (like List.Contains), you can also pass the base comparer (Comparer.OrdinalIgnoreCase) without wrapping it in Comparer.Equals.

Examples

Example 1: Case-insensitive equality check

let
    equalIgnoreCase = Comparer.Equals(Comparer.OrdinalIgnoreCase)
in
    equalIgnoreCase("hello", "HELLO")
Result
Result
1TRUE

Example 2: Use as a predicate to filter a list case-insensitively

let
    isEqual = Comparer.Equals(Comparer.OrdinalIgnoreCase),
    departments = {"Sales", "ENGINEERING", "marketing", "Engineering"},
    filtered = List.Select(departments, each isEqual(_, "engineering"))
in
    filtered
Applied Steps

The final output — a list containing the two entries that match "engineering" regardless of casing.

Result
1ENGINEERING,Engineering

Example 3: Case-insensitive distinct values from a list

List.Distinct({"East", "EAST", "West", "west", "East"}, Comparer.OrdinalIgnoreCase)
Result
Result
1East,West

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks