Character.FromNumber

D

T

The M Code Behind the Power Query M function Character.FromNumber

What is Power Query M?

Power Query M is a functional programming language used in Power Query, a data transformation and analysis tool available in Excel and Power BI. M is designed to work with data structures like tables, lists, and records, and can be used to transform and manipulate data in a variety of ways.

Introducing the Character.FromNumber Function

The Character.FromNumber function is one of the many functions available in Power Query M. It allows you to convert a number to a character based on its Unicode value. The function takes a single argument, the number to be converted, and returns the corresponding character.

Here is an example of how the Character.FromNumber function can be used to convert the Unicode value 65 to the character “A”:


Character.FromNumber(65)


The function returns the character "A".

How the Function Works

The M code behind the Character.FromNumber function is relatively simple. Here is the code:


(characterCode as number) as text => Character.FromUnicodeNumber(characterCode)


Let's break down this code. The function takes a single argument called characterCode, which is a number. This number represents the Unicode value of the character to be returned.

The function then calls the Character.FromUnicodeNumber function, passing in the characterCode argument. This function returns the character corresponding to the Unicode value.

Using the Function in Data Transformation

The Character.FromNumber function can be extremely useful in data transformation. For example, you may have a dataset that includes numerical codes for certain values, and you want to convert these codes to their corresponding characters.

Here is an example of how you can use the Character.FromNumber function to achieve this:


let

Source = Excel.CurrentWorkbook(){[Name=”MyTable”]}[Content],

Converted = Table.TransformColumns(Source, {“Code”, each Character.FromNumber(_)})

in

Converted


In this example, we are assuming that our dataset is named "MyTable" and contains a column called "Code" that includes numerical codes. We use the Table.TransformColumns function to transform the "Code" column by calling the Character.FromNumber function on each value in the column.

The result is a new table that includes the same data as the original table, but with the numerical codes replaced by their corresponding characters.

The Character.FromNumber function is a powerful tool for data transformation in Power Query M. It allows you to convert numerical codes to their corresponding characters based on their Unicode values. The M code behind the function is relatively simple, but it can be used in a variety of ways to transform and manipulate data.

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)