Comparer.Equals
ComparerReturns a comparer function that tests equality using the given base comparer.
Syntax
Comparer.Equals(comparer as function) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
comparer | function | Yes | A comparer function (such as Comparer.Ordinal or Comparer.OrdinalIgnoreCase) that defines the equality rules. |
Return Value
function — A 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 | |
|---|---|
| 1 | TRUE |
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
filteredThe final output — a list containing the two entries that match "engineering" regardless of casing.
Result | |
|---|---|
| 1 | ENGINEERING,Engineering |
Example 3: Case-insensitive distinct values from a list
List.Distinct({"East", "EAST", "West", "west", "East"}, Comparer.OrdinalIgnoreCase)Result | |
|---|---|
| 1 | East,West |