Comparer.Ordinal
Compares two values exactly, text character by character by its code: capitals before small letters.
Group: Splitters, combiners, replacers and comparers. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Comparer.Ordinal(x as any, y as any) as number
| Parameter | Type | Description |
|---|---|---|
x | any | The first value. |
y | any | The second value. |
Returns
number. -1 when x comes first, 0 when they are equal, 1 when y comes first.
Remarks
- It is the comparison M uses by default. Pass it where a function takes a comparer:
List.Sort,List.Distinct,List.Contains,Comparer.Equalsand others. - All capitals come before all small letters: "Cherry" sorts before "banana".
Examples
A capital comes first
Comparer.Ordinal("apple", "Banana")
1
Sorting by code
List.Sort({"banana", "Apple", "Cherry"}, Comparer.Ordinal)
{"Apple", "Cherry", "banana"}
Related functions
Comparer.OrdinalIgnoreCase, Comparer.FromCulture, Comparer.Equals, List.Sort.