Binary.Range
BinaryReturns a subset of a binary value beginning at a given offset.
Syntax
Binary.Range(binary as binary, offset as number, optional count as nullable number) as binaryParameters
| Name | Type | Required | Description |
|---|---|---|---|
binary | binary | Yes | The binary value to extract a subset from. |
offset | number | Yes | The zero-based byte position at which to begin the subset. |
count | number | No | The maximum number of bytes to include. If omitted, all bytes from the offset to the end are returned. |
Return Value
binary — A 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
AsListApplied 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
AsListApplied 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