BinaryFormat.Choice

D

T

The M Code Behind the Power Query M function BinaryFormat.Choice

What is BinaryFormat.Choice?

BinaryFormat.Choice is a function in Power Query that allows you to format binary data. It’s particularly useful when working with data that has been stored in a binary format, such as PDFs, images, or compressed files. With BinaryFormat.Choice, you can extract specific pieces of data from a binary file and format them in a meaningful way.

The Syntax of BinaryFormat.Choice

Before we dive into the M code behind BinaryFormat.Choice, let’s take a quick look at its syntax. Here’s an example of how to use BinaryFormat.Choice:


BinaryFormat.Choice(binary, choices)


The first argument, 'binary', is the binary data that you want to format. The second argument, 'choices', is a list of options that you want to extract from the binary data. Each option in the list should be a tuple that specifies the format of the option and the number of bytes it occupies.

The M Code Behind BinaryFormat.Choice

Now that we understand the syntax of BinaryFormat.Choice, let's take a closer look at its M code. Here's an example:


BinaryFormat.Choice(

binary,

{{

{0, 1},

{1, 1},

{2, 4},

{6, 1},

{7, 1}

}}

)


In this example, we're using BinaryFormat.Choice to extract five options from the binary data. Let's break down the M code step by step:

1. The first argument, 'binary', is simply a reference to the binary data that we want to format.

2. The second argument is a list of options that we want to extract from the binary data. Each option is specified as a tuple, which consists of two elements: the format of the option, and the number of bytes it occupies.

3. In this example, the first option is specified as `{0, 1}`. This means that the option is a single byte (`1`), and it should be formatted as an unsigned integer (`0`).

4. The second option is specified as `{1, 1}`. This means that the option is a single byte (`1`), and it should be formatted as an unsigned integer (`1`).

5. The third option is specified as `{2, 4}`. This means that the option is a four-byte integer (`4`), and it should be formatted as a signed integer (`2`).

6. The fourth option is specified as `{6, 1}`. This means that the option is a single byte (`1`), and it should be formatted as an unsigned integer (`6`).

7. The fifth option is specified as `{7, 1}`. This means that the option is a single byte (`1`), and it should be formatted as an unsigned integer (`7`).

BinaryFormat.Choice is a powerful function in Power Query that allows you to extract and format data from binary files. By understanding the M code behind this function, you can gain a deeper understanding of its capabilities and use it more effectively in your data analysis. With practice, you can unlock the full potential of BinaryFormat.Choice and take your data analysis to the next level.

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)