BinaryFormat.List
BinaryReturns a binary format that reads a sequence of items and returns a list.
Syntax
BinaryFormat.List(binaryFormat as function, optional countOrCondition as any) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
binaryFormat | function | Yes | The binary format of each item in the list. |
countOrCondition | any | No | The 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
function — A 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
trueto continue reading orfalseto stop. The final item (the one that causedfalse) 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