BinaryFormat.List

Binary

Returns a binary format that reads a sequence of items and returns a list.

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

Syntax

BinaryFormat.List(binaryFormat as function, optional countOrCondition as any) as function

Parameters

NameTypeRequiredDescription
binaryFormatfunctionYesThe binary format of each item in the list.
countOrConditionanyNoThe number of items to read, a function that returns true to continue or false to stop, or a binary format that reads the count preceding the list. If omitted, reads until end of data.

Return Value

functionA binary format function that reads a sequence of items and returns them as a list.

Remarks

BinaryFormat.List returns a binary format that reads a sequence of items from binary data and returns them as a list. The binaryFormat parameter defines how each individual item is read.

The countOrCondition parameter controls how many items are read:

  • Not specified -- Reads items until there is no more data.
  • A number -- Reads exactly that many items.
  • A function -- Called for each item read; returns true to continue reading or false to stop. The final item (the one that caused false) is included in the list.
  • A binary format -- The item count is read from the stream first using that format, then that many items are read.

This is one of the most commonly used composite binary formats, enabling you to read arrays or sequences of identically-formatted values from binary data.

Examples

Example 1: Read all bytes until end of data

let
    binaryData = #binary({1, 2, 3}),
    listFormat = BinaryFormat.List(BinaryFormat.Byte)
in
    listFormat(binaryData)

Example 2: Read a fixed number of items

let
    binaryData = #binary({1, 2, 3}),
    listFormat = BinaryFormat.List(BinaryFormat.Byte, 2)
in
    listFormat(binaryData)

Example 3: Read until a condition is met

let
    binaryData = #binary({1, 2, 3}),
    listFormat = BinaryFormat.List(BinaryFormat.Byte, (x) => x < 2)
in
    listFormat(binaryData)

Compatibility

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