Binary.ToText

Binary

Encodes binary data as Base64 or hexadecimal text.

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

Syntax

Binary.ToText(binary as nullable binary, optional encoding as nullable number) as nullable text

Parameters

NameTypeRequiredDescription
binarybinaryYesThe binary value to encode as text.
encodingnumberNoThe encoding format: BinaryEncoding.Base64 (default) or BinaryEncoding.Hex.

Return Value

textThe text representation of the binary value.

Remarks

Binary.ToText converts a binary value into a text string using either Base64 or hexadecimal encoding. This is the inverse of Binary.FromText.

- BinaryEncoding.Base64 (default) — produces a standard Base64 string. - BinaryEncoding.Hex — produces a hexadecimal string (uppercase).

Common use cases include encoding file content for embedding in JSON payloads or generating checksums for display.

Examples

Example 1: Encode text as Base64

let
    Original = "Power Query",
    AsBinary = Binary.From(Original),
    Base64 = Binary.ToText(AsBinary, BinaryEncoding.Base64)
in
    #table({"Original", "Base64"}, {{Original, Base64}})
Result
Original
Base64
1Power QueryUG93ZXIgUXVlcnk=

Example 2: Encode text as hexadecimal

let
    Original = "Hello",
    AsBinary = Binary.From(Original),
    Hex = Binary.ToText(AsBinary, BinaryEncoding.Hex)
in
    #table({"Original", "Hex"}, {{Original, Hex}})
Result
Original
Hex
1Hello48656C6C6F

Compatibility

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