Binary.From

Binary.From

D

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

Understanding Binary Data

Before we dive into the M code behind Binary.From, let’s first understand what binary data is and why it’s important. Binary data is any data stored in binary format, which is a system of representing data using only two digits: 0 and 1. This system is used by computers to store and manipulate data at the lowest level.

Binary data is commonly used for storing images, audio, and video files, as well as other types of data that require a high level of precision. It’s also used in encryption algorithms, where it provides a way to securely store and transmit sensitive information.

The Binary.From Function

The Binary.From function in Power Query is used to convert binary data into a text format. The function takes a binary value as input and returns a text value. The syntax of the function is as follows:


Binary.From(binary as binary) as text


The function takes a single parameter, binary, which is the binary value to be converted. The binary value can be any valid binary data, such as a binary file or a binary string.

The M Code Behind Binary.From

Now that we understand what Binary.From does, let’s take a closer look at the M code behind the function. The M code is what Power Query uses to perform the actual conversion from binary to text.

Here’s the M code for Binary.From:


let

Source = #binary({0}),

Value = Source{0},

Text = Text.From(Value)

in

Text


Let’s break down what’s happening in this code. First, a binary value is passed into the function as the Source parameter. This binary value is then converted into a list using the following code:


#binary({0})


This creates a list with a single element, which is the binary value passed in as the Source parameter. The list is then assigned to the Value variable using the following code:


Value = Source{0}


The {0} index is used to select the first element in the list, which is the binary value we want to convert. Finally, the binary value is converted into text using the Text.From function:


Text = Text.From(Value)


This converts the binary value into a text format, which is then returned as the output of the Binary.From function.

Use Cases for Binary.From

Now that we understand the M code behind Binary.From, let’s explore some of its use cases. Here are a few examples:

Converting Binary Files

One of the most common use cases for Binary.From is converting binary files into a text format. For example, let’s say you have a binary file that contains data in a proprietary format. You can use Binary.From to convert the file into a text format that can be easily manipulated and analyzed using Power Query.

Working with Encryption

Binary.From can also be useful when working with encryption algorithms. For example, let’s say you have an encrypted message that has been encoded in binary format. You can use Binary.From to convert the binary data into a text format, which can then be decrypted using a separate algorithm.

Converting Binary Strings

Finally, Binary.From can be used to convert binary strings into a text format. A binary string is a sequence of 0s and 1s that represents binary data. You can use Binary.From to convert the binary string into a text format that can be easily manipulated and analyzed using Power Query.

In this article, we’ve explored the M code behind the Power Query M function Binary.From. We’ve learned what binary data is, why it’s important, and how Binary.From can be used to convert binary data into a text format. We’ve also explored several use cases for Binary.From, including converting binary files, working with encryption, and converting binary strings. By understanding the M code behind Binary.From, you’ll be better equipped to use this powerful function in your own data analysis and manipulation workflows.

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)