BinaryFormat.Text

BinaryFormat.Text is a function in the Power Query M language that reads a text value based on the specified length and encoding. The function returns a binary format that decodes the text using the provided parameters.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

BinaryFormat.Text(
   length as any,
   optional encoding as nullable number,
) as function

Description

Returns a binary format that reads a text value. The length specifies the number of bytes to decode, or the binary format of the length that precedes the text. The optional encoding value specifies the encoding of the text. If the encoding is not specified, then the encoding is determined from the Unicode byte order marks. If no byte order marks are present, then TextEncoding.Utf8 is used.

Examples

Decode two bytes as ASCII text.

// Output: "AB"
let
    binaryData = #binary( {65, 66, 67} ),
    textFormat = BinaryFormat.Text( 2, TextEncoding.Ascii )
in
    textFormat( binaryData )

Decode ASCII text where the length of the text in bytes appears before the text as a byte.

// Output: "AB"
let
    binaryData = #binary( {2, 65, 66} ),
    textFormat = BinaryFormat.Text( 
        BinaryFormat.Byte,
        TextEncoding.Ascii
     )
in
    textFormat( binaryData )

Other functions related to BinaryFormat.Text are:

BI Gorilla Youtube Channel

Last update: August 25, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/binaryformat-text
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.