The M Code Behind the Power Query M function Lines.FromBinary

What is Lines.FromBinary?

Lines.FromBinary is a Power Query M function that converts binary data into lines of text. It is particularly useful when working with text files that have been encoded in binary format. By converting the binary data into text lines, it becomes easier to read and manipulate the data in Power BI.

The M Code Behind Lines.FromBinary

The M code behind Lines.FromBinary is relatively simple. It consists of a single line of code that uses the Binary.Buffer and Text.FromBinary functions to convert the binary data into text lines. Here is the code:


Source = Binary.Buffer(BinaryData),

Result = Text.FromBinary(Source)



The code starts with the 'let' statement, which creates a variable called 'Source' and assigns it the value of the binary data. The Binary.Buffer function is used to ensure that the binary data is loaded into memory before the conversion process begins. This can help to improve the performance of the function.

Next, the 'Result' variable is created and assigned the value of the Text.FromBinary function. This function takes the 'Source' variable as its input and converts it into text lines.

Finally, the 'in' statement is used to return the 'Result' variable as the output of the function. This output can then be used in other parts of the Power Query Editor to manipulate the data as required.

Using Lines.FromBinary

To use Lines.FromBinary, you first need to have binary data that you want to convert. This data can be stored in a variety of formats, including files, databases, and APIs.

Once you have the binary data, you can use Power Query Editor to create a new query. In the query editor, select the 'From Binary' option from the 'New Source' dropdown menu. This will open a dialog box where you can enter the location of the binary data.

Once you have loaded the binary data into the query editor, you can use the 'Lines.FromBinary' function to convert it into text lines. To do this, simply select the column containing the binary data and click on the 'Add Column' tab in the ribbon. From there, select 'Custom Column' and enter the M code for the function.

Once the function has been applied, you should see a new column containing the text lines created from the binary data.

In conclusion, Lines.FromBinary is a powerful function in Power Query M that allows users to convert binary data into text lines. Its M code is relatively simple and easy to understand, making it accessible to users of all skill levels. By understanding the M code behind this function, users can better understand how it works and how it can be used to manipulate data in Power BI.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)