---
title: Binary.Decompress – ยกเลิกการบีบอัดข้อมูลไบนารี่
url: https://www.thepexcel.com/functions/power-query/binary-functions/binary-decompress/
type: function-explainer
program: Power Query
syntax: "= Binary.Decompress(binary, compressionType)"
date: 2025-12-12
updated: 2025-12-25
scores:
  popularity: 4
  difficulty: 5
  usefulness: 5
---

# Binary.Decompress – ยกเลิกการบีบอัดข้อมูลไบนารี่

> Binary.Decompress ยกเลิกการบีบอัดข้อมูลไบนารี่ที่ถูกบีบอัดด้วย GZip หรือ Deflate กลับเป็นข้อมูลต้นฉบ

## คำอธิบาย

Binary.Decompress ยกเลิกการบีบอัดข้อมูลไบนารี่ที่ถูกบีบอัดด้วย GZip หรือ Deflate กลับเป็นข้อมูลต้นฉบับ

## Syntax

```excel
= Binary.Decompress(binary, compressionType)
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| binary | Yes | binary |  | ข้อมูลไบนารี่ที่ถูกบีบอัดแล้ว |
| compressionType | Yes | number |  | ประเภทการบีบอัดที่ใช้ (Compression.GZip หรือ Compression.Deflate) |

## ตัวอย่าง

### 1. ยกเลิกการบีบอัด Deflate แบบง่ายๆ

```excel
= Binary.Decompress(
    #binary({115, 103, 200, 7, 194, 20, 134, 36, 134, 74, 134, 84, 6, 0}),
    Compression.Deflate
)
```

**ผลลัพธ์:** `#binary({71, 0, 111, 0, 111, 0, 100, 0, 98, 0, 121, 0, 101, 0})`

ยกเลิกการบีบอัด Deflate จาก binary ที่มี 14 bytes กลับเป็นข้อมูลต้นฉบับ ผลลัพธ์เป็น binary ที่ไม่ได้บีบอัด

### 2. ยกเลิกการบีบอัด GZip ในโครงสร้าง let...in

```excel
let
    CompressedData = #binary({31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 75, 44, 0, 0}),
    Decompressed = Binary.Decompress(CompressedData, Compression.GZip)
in
    Decompressed
```

**ผลลัพธ์:** `binary ที่ไม่ได้บีบอัดแล้ว`

บันทึก binary ที่บีบอัดด้วย GZip ในตัวแปร จากนั้นใช้ Binary.Decompress ยกเลิกการบีบอัด แล้วส่งกลับข้อมูลต้นฉบับ

### 3. ยกเลิกการบีบอัดจาก Web API Response

```excel
let
    Response = Json.Document(
        Web.Contents("https://api.example.com/data")
    ),
    CompressedBinary = Response[compressed_data],
    Decompressed = Binary.Decompress(CompressedBinary, Compression.Deflate),
    Text = Binary.ToText(Decompressed, BinaryEncoding.Utf8)
in
    Text
```

**ผลลัพธ์:** `ข้อความที่อ่านได้จากข้อมูลบีบอัด`

ดึงข้อมูล binary ที่บีบอัดมาจาก API ยกเลิกการบีบอัด แล้วแปลง binary เป็น text ด้วย Binary.ToText

### 4. ตรวจสอบประเภทการบีบอัดก่อนยกเลิก

```excel
let
    CompressedData = #binary({115, 103, 200, 7}),
    CompressionMethod = Compression.Deflate,
    Decompressed = try Binary.Decompress(CompressedData, CompressionMethod)
                   otherwise null
in
    Decompressed
```

**ผลลัพธ์:** `binary ที่ไม่ได้บีบอัด หรือ null ถ้าเกิดข้อผิดพลาด`

ใช้ try...otherwise เพื่อป้องกันข้อผิดพลาด ถ้าข้อมูลไม่ได้บีบอัดตรงกับประเภทที่ระบุ

## หมายเหตุเพิ่มเติม

- ผมแนะนำให้ใช้ try...otherwise ครอบ Binary.Decompress ไว้เสมอ เพื่อป้องกันข้อผิดพลาด

- ถ้าข้อมูลเป็น text ที่ถูกบีบอัด ให้ใช้ Binary.ToText หรือ Binary.FromText ร่วมด้วย

- ส่วนตัวผมใช้ฟังก์ชันนี้กับ Web.Contents ที่มีข้อมูล GZip ส่วนใหญ่ เพราะ API บางตัวส่ง compress data มาเอง

- ตรวจสอบ compressionType ให้ถูกต้องเสมอ ไม่งั้น Error จะสับสน

## คำถามที่พบบ่อย

**Q: ต่างจาก Binary.Compress อย่างไร?**

Binary.Compress บีบอัดข้อมูลให้เล็กลง ส่วน Binary.Decompress ยกเลิกการบีบอัดให้กลับมาใช้ได้ เป็นฟังก์ชันตรงข้ามกัน ผมแนะนำให้ใช้ Compress เวลาต้องการส่งข้อมูลขนาดใหญ่ ใช้ Decompress เวลาต้องการแตกไฟล์ที่ได้รับมา

**Q: ต้องใช้ Compression.GZip หรือ Compression.Deflate อันไหน?**

มันขึ้นอยู่กับว่าข้อมูลถูกบีบอัดด้วยวิธีไหนมา ถ้าบีบอัดด้วย GZip ต้องใช้ Compression.GZip โดยการผิดพลาดจะถูก Error อย่างชัดเจน ผมแนะนำให้ดู file header หรือขอเอกสารจากแหล่งข้อมูล

**Q: ถ้าข้อมูลไม่ได้บีบอัดหรือบีบอัดแบบผิดจะเกิดอะไร?**

จะ Error ออกมา ผมแนะนำให้ใช้ try...otherwise ครอบไว้ เพื่อไม่ให้ query หยุดชะงัก

**Q: สามารถใช้กับข้อมูลขนาดใหญ่ได้หรือเปล่า?**

ได้ แต่ Power Query ต้องมีหน่วยความจำพอ ผมเคยใช้กับไฟล์ที่บีบอัด 100MB ไม่มีปัญหา แต่ต้องแน่ใจว่า refresh ไม่ timeout

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn: Binary.Decompress](https://learn.microsoft.com/en-us/powerquery-m/binary-decompress) _(official)_
- [Microsoft Learn: Compression.Deflate](https://learn.microsoft.com/en-us/powerquery-m/compression-deflate) _(official)_
- [Microsoft Learn: Binary.Compress](https://learn.microsoft.com/en-us/powerquery-m/binary-compress) _(official)_

---

_Source: [https://www.thepexcel.com/functions/power-query/binary-functions/binary-decompress/](https://www.thepexcel.com/functions/power-query/binary-functions/binary-decompress/)_
