Binary.Range

Binary

Returns a subset of a binary value beginning at a given offset.

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

Syntax

Binary.Range(binary as binary, offset as number, optional count as nullable number) as binary

Parameters

NameTypeRequiredDescription
binarybinaryYesThe binary value to extract a subset from.
offsetnumberYesThe zero-based byte position at which to begin the subset.
countnumberNoThe maximum number of bytes to include. If omitted, all bytes from the offset to the end are returned.

Return Value

binaryA binary value containing the specified subset of bytes.

Remarks

Binary.Range returns a subset of a binary value starting at the specified zero-based offset. An optional count parameter limits the number of bytes returned. If count is omitted, all bytes from the offset to the end of the binary are included.

This function is useful for extracting specific portions of binary data, such as reading a fixed-size header from a binary stream.

Examples

Example 1: Extract bytes from a specific offset

let
    Source = Binary.FromList({0..10}),
    Subset = Binary.Range(Source, 6),
    AsList = Binary.ToList(Subset)
in
    AsList
Applied Steps

Converts the subset binary to a list for inspection.

Value
1{6, 7, 8, 9, 10}

Example 2: Extract a specific number of bytes

let
    Source = Binary.FromList({0..10}),
    Subset = Binary.Range(Source, 6, 2),
    AsList = Binary.ToList(Subset)
in
    AsList
Applied Steps

Converts the subset binary to a list, confirming {6, 7}.

Value
1{6, 7}

Compatibility

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