Binary.FromText

Binary

Decodes text encoded as Base64 or hexadecimal into a binary value.

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

Syntax

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

Parameters

NameTypeRequiredDescription
texttextYesThe Base64 or hex-encoded text to decode.
encodingnumberNoThe binary encoding format: BinaryEncoding.Base64 (default) or BinaryEncoding.Hex.

Return Value

binaryThe binary value decoded from the text.

Remarks

Binary.FromText decodes a text string that represents binary data in Base64 or hexadecimal format. The encoding parameter determines which format to expect:

- BinaryEncoding.Base64 (default) — standard Base64 encoding (e.g., "SGVsbG8="). - BinaryEncoding.Hex — hexadecimal encoding (e.g., "48656C6C6F").

This is commonly used when APIs return binary data encoded as Base64 strings (e.g., image data, file attachments).

Examples

Example 1: Decode Base64 text

let
    Base64Text = "SGVsbG8gV29ybGQ=",
    Decoded = Binary.FromText(Base64Text, BinaryEncoding.Base64),
    AsText = Text.FromBinary(Decoded)
in
    #table({"Encoded", "Decoded"}, {{Base64Text, AsText}})
Result
Encoded
Decoded
1SGVsbG8gV29ybGQ=Hello World

Example 2: Decode hexadecimal text

let
    HexText = "48656C6C6F",
    Decoded = Binary.FromText(HexText, BinaryEncoding.Hex),
    AsText = Text.FromBinary(Decoded)
in
    #table({"Hex", "Decoded"}, {{HexText, AsText}})
Result
Hex
Decoded
148656C6C6FHello

Compatibility

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