Binary.Compress

Binary

Compresses a binary value using the specified compression type (GZip or Deflate).

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

Syntax

Binary.Compress(binary as nullable binary, compressionType as number) as nullable binary

Parameters

NameTypeRequiredDescription
binarybinaryYesThe binary value to compress.
compressionTypenumberYesThe compression algorithm to use: Compression.GZip or Compression.Deflate.

Return Value

binaryA compressed copy of the input binary value.

Remarks

Binary.Compress compresses a binary value using the specified compression algorithm. The result is a compressed copy of the input. Supported compression types are:

  • Compression.GZip — GZip compression (RFC 1952). Produces output with a GZip header/trailer; commonly used for HTTP content encoding.
  • Compression.Deflate — Deflate compression (RFC 1951). Produces raw compressed output without headers.

Use Binary.Decompress with the same compression type to reverse the operation. This pair of functions is useful for reducing the size of binary data for storage or transmission.

Examples

Example 1: Compress a binary value using Deflate

let
    Source = Binary.FromList(List.Repeat({10}, 1000)),
    Compressed = Binary.Compress(Source, Compression.Deflate),
    OriginalSize = Binary.Length(Source),
    CompressedSize = Binary.Length(Compressed)
in
    #table({"OriginalBytes", "CompressedBytes"}, {{OriginalSize, CompressedSize}})
Applied Steps

The final output — a single-row table comparing the original and compressed sizes.

OriginalBytes
CompressedBytes
11,00011

Compatibility

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