Int8.From

D

T

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

Understanding Int8.From

The Int8.From function in Power Query is used to convert text values to 8-bit integers. The function takes a single argument, which is the text value to be converted. Here’s the basic syntax of the function:


Int8.From(text as text) as nullable number


The function returns a nullable number, which means that it can return a number or a null value. If the text value cannot be converted to an 8-bit integer, the function will return a null value.

The M Code Behind Int8.From

To understand how the Int8.From function works, we need to take a look at the M code behind it. The M code is the code that Power Query uses to perform data transformations.

Here's the M code behind the Int8.From function:


(text) => Number.From(Text.Remove(text, {” “}), “en-US”)


Let's break down this code to understand what it does.

Breaking Down the M Code

The M code for the Int8.From function is a lambda function. A lambda function is a small anonymous function that can be used to create more complex functions. The lambda function takes a single argument, which is the text value to be converted.

The first part of the M code is:


Text.Remove(text, {” “})


This part of the code removes any spaces from the text value. It's important to remove spaces before converting the text value to a number because spaces can cause errors in the conversion process.

The second part of the M code is:


Number.From(Text.Remove(text, {” “}), “en-US”)


This part of the code converts the text value to a number. The Number.From function is used to convert the text value to a number. The "en-US" argument is used to specify the culture of the number. In this case, "en-US" specifies the culture as English (United States).

Using Int8.From

Now that we understand the M code behind the Int8.From function, let's take a look at how to use it in Power Query.

To use the Int8.From function, we first need to create a new query in Power Query. Once we have our new query, we can add a new step and select the Int8.From function from the list of available functions.

Here's an example of how to use the Int8.From function:


let

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

#”Converted to Int8″ = Table.TransformColumns(Source,{{“Column1”, Int8.From, type nullable number}})

in

#”Converted to Int8″


In this example, we're using the Int8.From function to convert the values in "Column1" to 8-bit integers. The "type nullable number" argument is used to specify the data type of the new column.

The Int8.From function is a powerful tool in Power Query that allows users to convert text values to 8-bit integers. By understanding the M code behind the function, we can gain a deeper understanding of how it works and how to use it in our data transformations.

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)