BinaryFormat.Binary

Binary

Returns a binary format that reads a binary value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

BinaryFormat.Binary(optional length as any) as function

Parameters

NameTypeRequiredDescription
lengthanyNoThe number of bytes to read, or a binary format that reads the length preceding the binary data. If not specified, reads the remaining bytes.

Return Value

functionA binary format function that reads a binary value of the specified length.

Remarks

BinaryFormat.Binary returns a binary format that reads a binary value from the input. The length parameter controls how many bytes are read:

  • If length is not specified, all remaining bytes in the binary stream are read.
  • If length is a number, that exact number of bytes is read.
  • If length is a binary format (such as BinaryFormat.Byte or BinaryFormat.UnsignedInteger32), the length value is read first from the stream using that format, and then that many bytes of binary data are read.

This is useful when extracting raw binary chunks from a larger binary stream, such as reading embedded images or binary blobs from a structured file format.

Examples

Example 1: Read a fixed number of binary bytes

let
    binaryData = #binary({0x48, 0x65, 0x6C, 0x6C, 0x6F}),
    format = BinaryFormat.Binary(2)
in
    format(binaryData)

Example 2: Read binary data with a length prefix

let
    binaryData = #binary({3, 0x41, 0x42, 0x43, 0xFF}),
    format = BinaryFormat.Binary(BinaryFormat.Byte)
in
    format(binaryData)

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks