Comparer.FromCulture

D

T

The M Code Behind the Power Query M function Comparer.FromCulture

The Comparer.FromCulture function is used to compare and sort text values in Power Query M based on a specific culture. This function is useful when dealing with text values that are in different languages or when sorting data based on a specific cultural ordering. In this article, we will take a closer look at the M code behind the Comparer.FromCulture function and how it works.

Understanding the Comparer.FromCulture Function

The Comparer.FromCulture function is part of the Text library in Power Query M and is used to create a comparer that compares two values based on a specific culture. The function takes a single argument, which is the culture to be used for comparison.

The syntax for the Comparer.FromCulture function is as follows:


Comparer.FromCulture(culture as text) as function


The culture parameter is a text value that specifies the culture to be used for comparison. This value can be any valid culture name or language identifier, such as en-US or fr-FR.

The function returns a comparer function that can be used to compare two values based on the specified culture. The comparer function takes two arguments, which are the values to be compared, and returns a result based on the comparison.

Using the Comparer.FromCulture Function in Power Query M

The Comparer.FromCulture function is used in Power Query M to compare and sort text values based on a specific culture. This function is useful when dealing with text values that are in different languages or when sorting data based on a specific cultural ordering.

To use the Comparer.FromCulture function in Power Query M, you need to first create a comparer function by calling the function with the desired culture. This comparer function can then be used in various functions that require a comparer, such as List.Sort or List.Max.

For example, consider the following Power Query M code that sorts a list of text values in French:


let

Source = {“Bonjour”, “Ça va?”, “Comment ça va?”, “Au revoir”, “À bientôt”},

Sorted = List.Sort(Source, Comparer.FromCulture(“fr-FR”))

in

Sorted


In this code, the List.Sort function is used to sort a list of text values in French. The Comparer.FromCulture function is called with the "fr-FR" culture to create a comparer function that compares text values based on French ordering. This comparer function is then used as the second argument to the List.Sort function to sort the list based on French ordering.

The Comparer.FromCulture function is a powerful tool in Power Query M that allows you to compare and sort text values based on a specific culture. This function is essential when dealing with text values that are in different languages or when sorting data based on a specific cultural ordering. By understanding the M code behind the Comparer.FromCulture function, you can use it effectively in your Power Query M code to clean and transform data with ease.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)