The M Code Behind the Power Query M function Int16.From

Understanding Int16.From

Before we dive into the M code, let’s first understand what Int16.From does. This function takes a value as input and converts it to a 16-bit integer. The resulting integer can range from -32,768 to 32,767.

Here’s an example of how Int16.From is used:


In this example, the value 1234 is converted to a 16-bit integer.

The M Code Behind Int16.From

Now that we have a basic understanding of what Int16.From does, let's explore the M code behind it. The M code for Int16.From is quite simple:

(Int16.From as any) (value as any) =>


result = Int16.From(value)



Let's break down what each line of this code does:

- `(Int16.From as any)`: This line defines the function name and input parameter type. In this case, the function name is Int16.From and the input parameter type is any.

- `(value as any)`: This line defines the input parameter name as value and the type as any.

- `result = Int16.From(value)`: This line performs the actual conversion of the input value to a 16-bit integer and stores the result in a variable called result.

- `result`: This line returns the result of the function.

Using Int16.From in Power Query

Now that we understand the M code behind Int16.From, let's take a look at how it can be used in Power Query.

Suppose we have a column of values in our Power Query data that we want to convert to 16-bit integers. We can use the Int16.From function to do this. Here's an example:


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

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Column1”, Int16.Type}})


#”Changed Type”

In this example, we first define our data source as a table called Table1. We then use the Table.TransformColumnTypes function to transform the data type of Column1 to Int16. This is where we use the Int16.Type function, which is equivalent to using Int16.From.

The Int16.From function in Power Query is a simple yet powerful tool for converting values to 16-bit integers. Understanding the M code behind this function can help you better utilize it in your Power Query projects. By using Int16.From, you can ensure that your data is transformed correctly and efficiently.

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

Upcoming Courses

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)