Value.Compare
Which of two values comes first: -1, 0 or 1.
Group: Values, types and errors. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Value.Compare(value1 as any, value2 as any, optional precision as nullable number) as number
| Parameter | Type | Description |
|---|---|---|
value1 | any | The first value. |
value2 | any | The second value. |
precision | nullable number optional | Precision.Double (the default) or Precision.Decimal. |
Returns
number. -1 when the first value is smaller, 0 when they are equal, 1 when it is larger.
Remarks
- Text is compared character by character by code: "10" comes before "9", and capitals before small letters. Use
Comparer.OrdinalIgnoreCaseto ignore case. - A function of two values that gives -1, 0 or 1 is what
List.SortandTable.Sorttake to order by a rule of your own.
Examples
Dates
Value.Compare(#date(2026, 3, 1), #date(2026, 2, 28))
1
Numbers written as text
Value.Compare("10", "9")
-1
As text, "1" comes before "9", so "10" is the smaller.
Highest first
List.Sort({120, 50, 340}, (x, y) => Value.Compare(y, x))
{340, 120, 50}