Comparer.FromCulture

Comparer

Returns a comparer function based on the specified culture and case-sensitivity setting.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Comparer.FromCulture(culture as text, optional ignoreCase as nullable logical) as function

Parameters

NameTypeRequiredDescription
culturetextYesA culture identifier string (e.g., "en-US", "de-DE", "fr-FR").
ignoreCaselogicalNoIf true, the comparer ignores case differences. Defaults to false.

Return Value

functionA comparer function that uses culture-specific linguistic rules for comparisons.

Remarks

Comparer.FromCulture returns a comparer function that applies culture-specific linguistic sorting rules. Unlike ordinal comparers that compare raw byte values, culture-aware comparers respect language-specific ordering (e.g., in German, "a" and "a" with an umlaut may sort adjacently).

Use this when your data contains locale-specific text and you need sorting or comparison that matches user expectations for that language.

Examples

Example 1: Culture-aware case-insensitive sort

let
    Categories = List.Distinct(Table.Column(Sales, "Category")),
    Sorted = List.Sort(Categories, Comparer.FromCulture("en-US", true))
in
    #table({"Category"}, List.Transform(Sorted, each {_}))
Result
Category
1Gadgets
2Misc
3Widgets

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks