Text.ToBinary

D

T

The M Code Behind the Power Query M function Text.ToBinary

What is Text.ToBinary?

Before we dive into the M code behind Text.ToBinary, let’s take a moment to understand what this function does. Text.ToBinary is a Power Query M function that converts a text string into a binary representation. This binary representation can then be used for various purposes such as encryption, compression, or storage.

The M Code Behind Text.ToBinary

The M code behind Text.ToBinary is relatively simple. Here is the code:


(Text as text, optional Encoding as nullable number) as binary =>

Binary.FromText(Text, Encoding)


As you can see, the Text.ToBinary function takes two arguments: Text and Encoding. The Text argument is the text string that you want to convert into a binary representation. The Encoding argument is optional and specifies the encoding to use for the conversion. If the Encoding argument is not provided, the function will use the default encoding for the current locale.

The core of the Text.ToBinary function is the Binary.FromText function. This function takes the text string and converts it into a binary representation. The optional Encoding argument specifies the encoding to use for the conversion. If the Encoding argument is not provided, the function will use the default encoding for the current locale.

Using Text.ToBinary

Using Text.ToBinary is straightforward. Here is an example:


let

textString = "Hello, world!",

binaryRepresentation = Text.ToBinary(textString)

in

binaryRepresentation


In this example, we define a text string “Hello, world!” and pass it as an argument to the Text.ToBinary function. The function returns a binary representation of the text string, which we store in the binaryRepresentation variable.

In conclusion, the Text.ToBinary function is a powerful tool for converting text strings into binary representations. Its simple M code makes it easy to use in Power Query, and its flexibility makes it applicable in a variety of scenarios. We hope that this article has helped you understand the M code behind Text.ToBinary and how to use it in your data analysis and business intelligence projects.

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)