BinaryFormat.Text

Updated on

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
Argument Attribute Description
length
encoding optional Uses the TextEncoding.Type to specify the text’s binary encoding format. By default, if not provided, the argument uses TextEncoding.Utf8 (UTF8 binary form). Other available options are:
TextEncoding.Unicode: use the UTF16 little-endian binary form.
TextEncoding.Utf16: use the UTF16 little-endian binary form.
TextEncoding.BigEndianUnicode: use the UTF16 big endian binary form.
TextEncoding.Windows: use the Windows binary form.
TextEncoding.Ascii: use the ASCII binary form.

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:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/binaryformat-text

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy