OpenBI Docs Buy

Comparer.FromCulture

Makes a comparer that orders and matches text by a culture's rules, with or without regard to case.

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.FromCulture(culture as text, optional ignoreCase as nullable logical) as function
ParameterTypeDescription
culturetextThe culture's name, such as "nb-NO" or "en-US".
ignoreCasenullable logical
optional
true to treat capitals and small letters as the same.

Returns

function. A comparer of two values, giving -1, 0 or 1, for List.Sort, Comparer.Equals and the others.

Compared with Power Query

OpenBI orders text by its characters' codes whatever the culture, by design: the same order everywhere, with ignoreCase the only option used. Power Query orders by the culture's alphabet, so a sort can come out differently: see the known difference below. Matching with ignoreCase gives the same answers.

Known difference in OpenBI Studio 0.3.79, found while this page was written and run on its engine:

  • List.Sort({"Ålesund", "Bergen", "Oslo"}, Comparer.FromCulture("en-US")): Power Query gives {"Ålesund", "Bergen", "Oslo"}: in English Å sorts as an A. OpenBI orders by character code, Å after Z, and gives {"Bergen", "Oslo", "Ålesund"} (by design). Likewise Comparer.FromCulture("en-US")("apple", "Banana") is -1 in Power Query and 1 in OpenBI.

Examples

Equal apart from case

Comparer.Equals(Comparer.FromCulture("en-US", true), "OSLO", "oslo")
true

Å comes last in Norwegian

List.Sort({"Ålesund", "Bergen", "Oslo"}, Comparer.FromCulture("nb-NO"))
{"Bergen", "Oslo", "Ålesund"}

Comparer.Ordinal, Comparer.OrdinalIgnoreCase, Comparer.Equals, List.Sort.

Last updated · OpenBI Studio 0.3.79