BinaryFormat.ByteOrder

Binary

Returns a binary format with the byte order specified by the given format.

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

Syntax

BinaryFormat.ByteOrder(binaryFormat as function, byteOrder as number) as function

Parameters

NameTypeRequiredDescription
binaryFormatfunctionYesThe binary format to apply the byte order to.
byteOrdernumberYesThe byte order to use. Use ByteOrder.LittleEndian or ByteOrder.BigEndian.

Return Value

functionA binary format function that reads data using the specified byte order.

Remarks

BinaryFormat.ByteOrder wraps a binary format to change its byte order (endianness). By default, multi-byte binary formats in Power Query use little-endian byte order (least significant byte first). Many network protocols and some file formats use big-endian byte order (most significant byte first) instead.

Use ByteOrder.BigEndian for big-endian data (network byte order) and ByteOrder.LittleEndian for little-endian data. This affects multi-byte integer and floating point format specifiers like BinaryFormat.UnsignedInteger16, BinaryFormat.SignedInteger32, BinaryFormat.Double, and similar formats.

Single-byte formats like BinaryFormat.Byte are unaffected by byte order since they read only one byte.

Examples

Example 1: Read a big-endian 16-bit unsigned integer

let
    // Big-endian: most significant byte first
    // 0x00, 0x01 = 1 in big-endian
    binaryData = #binary({0x00, 0x01}),
    format = BinaryFormat.ByteOrder(
        BinaryFormat.UnsignedInteger16,
        ByteOrder.BigEndian
    )
in
    format(binaryData)

Example 2: Read a big-endian record

let
    binaryData = #binary({
        0x00, 0x01,
        0x00, 0x00, 0x00, 0x02
    }),
    format = BinaryFormat.ByteOrder(
        BinaryFormat.Record([
            A = BinaryFormat.UnsignedInteger16,
            B = BinaryFormat.UnsignedInteger32
        ]),
        ByteOrder.BigEndian
    )
in
    format(binaryData)

Compatibility

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