Binary.Combine

Binary.Combine

D

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

What is Binary.Combine?

Binary.Combine is a function in Power Query that is used to combine multiple binary values into a single binary value. This function is often used in scenarios where data needs to be compressed or combined into a single value for storage or transmission.

The Binary.Combine function takes two or more binary values as input and returns a single binary value. The resulting binary value is the concatenation of the input binary values in the order they were passed to the function.

The M Code Behind Binary.Combine

The M code behind Binary.Combine is relatively simple, but it can be a bit confusing for those who are not familiar with the language. Here is the M code that powers Binary.Combine:


(Binary.Combine) =>

let

Output = Binary.FromText(List.Combine(List.Transform(Binary.ToList(Binary.Combine), each List.Buffer(_))))

in

Output


Let’s break down this code and explore what each part does.

The Function Definition

The first line of the M code defines the Binary.Combine function. This line tells Power Query that we are defining a new function called Binary.Combine. The “=>” symbol is used to separate the function definition from the function body.

The Function Body

The function body is the code that is executed when the Binary.Combine function is called. In this case, the function body consists of two parts: the “let” statement and the “in” statement.

#### The “let” Statement

The “let” statement is used to define variables that are used in the function body. In this case, we are defining a variable called “Output”.

The “Output” variable is set equal to the result of the “Binary.FromText” function.

#### The “in” Statement

The “in” statement is used to specify the output of the function. In this case, we are telling Power Query to output the value of the “Output” variable.

The Binary.FromText Function

The Binary.FromText function is used to convert a text value into a binary value. In this case, we are passing a value to the Binary.FromText function that is the result of the List.Combine function.

The List.Combine Function

The List.Combine function is used to combine two or more lists into a single list. In this case, we are passing a value to the List.Combine function that is the result of the List.Transform function.

The List.Transform Function

The List.Transform function is used to transform each value in a list using a specified function. In this case, we are passing a value to the List.Transform function that is the result of the Binary.ToList function.

The Binary.ToList Function

The Binary.ToList function is used to convert a binary value into a list of bytes. In this case, we are passing a value to the Binary.ToList function that is the result of the Binary.Combine function.

Putting It All Together

When we put all of these functions together, we end up with a function that takes two or more binary values as input, converts them into lists of bytes, combines the lists into a single list, converts the resulting list into a single binary value, and returns the binary value.

Binary.Combine is a powerful function in Power Query that is used to combine multiple binary values into a single binary value. The M code that powers Binary.Combine may seem a bit confusing at first, but with a little bit of exploration and practice, you’ll be able to understand and use this function with ease.

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)