Binary.View

Binary

Creates a custom view of a binary value with handler functions that override default operation behavior.

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

Syntax

Binary.View(binary as nullable binary, handlers as record) as binary

Parameters

NameTypeRequiredDescription
binarybinaryNoThe base binary value to create a view of. If null, the GetStream handler is required.
handlersrecordYesA record of handler functions that replace the default behavior of operations applied to the view.

Return Value

binaryA binary view where specified handler functions override default operation behavior.

Remarks

Binary.View creates a custom binary view where handler functions override the default behavior of operations applied to the binary. This is the binary-stream equivalent of Table.View and is primarily used in custom connector development to implement folding for binary data sources.

When an operation is applied to the view:

1. If a matching handler exists, it is called. 2. If the handler raises an error, the engine falls back to applying the operation against the base binary. Use Binary.ViewError to raise errors that bypass this fallback. 3. If no handler exists, the default behavior is applied to binary.

If binary is null, the GetStream handler is required since there is no base binary to fall back to.

Common handler functions include:

  • GetStream — returns the binary stream content. Called when the binary data is accessed.
  • GetLength — returns the length of the binary without reading the full stream.
  • GetExpression — returns the M expression representing the view.
  • OnInvoke — called when a view function (created via Binary.ViewFunction) is invoked on the view.

Refer to the published Power Query custom connector documentation for a complete description of Binary.View.

Examples

Example 1: Create a basic view with a custom length handler

let
    View = Binary.View(
        null,
        [
            GetLength = () => 12,
            GetStream = () => Text.ToBinary("hello world!")
        ]
    ),
    Len = Binary.Length(View)
in
    Len
Applied Steps

Calls Binary.Length on the view, which invokes the GetLength handler and returns 12 without reading the stream.

Value
112

Compatibility

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