OpenBI Docs Buy

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
ParameterTypeDescription
value1anyThe first value.
value2anyThe second value.
precisionnullable 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.OrdinalIgnoreCase to ignore case.
  • A function of two values that gives -1, 0 or 1 is what List.Sort and Table.Sort take 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}

Value.Equals, Comparer.Ordinal, List.Sort.

Last updated · OpenBI Studio 0.3.79