# Text.FromBinary

## #

One function in M that comes in handy is the Text.FromBinary function. This function is used to convert binary data into text format. In this article, we will explore the M code behind the Text.FromBinary function and understand how it works.

## Understanding Binary Data

Before we dive into the M code, let’s first understand what binary data is. Binary data is a sequence of 0s and 1s that computers use to represent data. It is the most basic form of data storage used by computers. Binary data is used to store text, images, videos, and any other type of data that computers process.

## The Text.FromBinary function

The Text.FromBinary function is used to convert binary data into text format. It takes in a binary value as an argument and returns a text value. The syntax for the Text.FromBinary function is as follows:

``` Text.FromBinary(binary as binary) as text ```

The binary argument is the binary data that needs to be converted, and the function returns the text representation of the binary data.

## The M Code Behind the Text.FromBinary function

Now that we understand what the Text.FromBinary function does, let’s take a look at the M code behind it. The M code for the Text.FromBinary function is as follows:

``` let Source = Binary.ToText(binary, BinaryEncoding.Base64) in Source ```

The M code consists of a single expression that uses the Binary.ToText function to convert binary data into text format. The Binary.ToText function takes in two arguments: the binary value that needs to be converted and the encoding that should be used to encode the binary data.

In the above M code, we are using the Base64 encoding to encode the binary data. Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. This encoding is commonly used for sending binary data over email or other text-based communication channels.

## Examples

Let’s take a look at some examples of how the Text.FromBinary function can be used in Power Query.

### Example 1

Suppose we have a binary value that represents the text “Hello, World!”. We can use the Text.FromBinary function to convert the binary data into text format as follows:

``` let binaryValue = Binary.FromText("SGVsbG8sIFdvcmxkIQ==", BinaryEncoding.Base64), textValue = Text.FromBinary(binaryValue) in textValue ```

The above M code will return the text value “Hello, World!”.

### Example 2

Suppose we have a table that contains a binary column, and we want to convert the binary data in the column into text format. We can use the Text.FromBinary function in conjunction with the Table.TransformColumns function as follows:

``` let Source = #table({"BinaryColumn"}, {{Binary.FromText("SGVsbG8sIFdvcmxkIQ==", BinaryEncoding.Base64)}}), Transform = Table.TransformColumns(Source, {{"BinaryColumn", each Text.FromBinary(_)}}) in Transform ```

The above M code will return a table with the binary column converted into text format.

The Text.FromBinary function in Power Query is a powerful tool for converting binary data into text format. It is an essential function for data transformation and data preparation tasks. By understanding the M code behind the Text.FromBinary function, you can gain a deeper understanding of how Power Query works and how to make the most of its advanced data manipulation capabilities.

Subject