---
title: Table.ExpandRecordColumn – ขยาย Record Column เป็นหลายคอลัมน์
url: https://www.thepexcel.com/functions/power-query/table-functions/table-expandrecordcolumn-3/
type: function-explainer
program: Power Query
syntax: "Table.ExpandRecordColumn(table as table, column as text, fieldNames as list, optional newColumnNames as nullable list) as table"
date: 2025-12-17
scores:
  popularity: 8
  difficulty: 4
  usefulness: 8
---

# Table.ExpandRecordColumn – ขยาย Record Column เป็นหลายคอลัมน์

> ขยาย Record column ออกเป็นหลายคอลัมน์แยกกัน

## คำอธิบาย

Table.ExpandRecordColumn ขยายคอลัมน์ที่เก็บ Record values ออกเป็นคอลัมน์แยกกัน โดยแต่ละฟิลด์ใน Record จะกลายเป็นคอลัมน์ใหม่ สามารถระบุว่าต้องการขยายฟิลด์ใดบ้างผ่าน fieldNames parameter และสามารถกำหนดชื่อคอลัมน์ใหม่ผ่าน newColumnNames เพื่อป้องกันชื่อซ้ำ มักใช้หลังจาก API calls หรือการ parse JSON ที่ได้ข้อมูลแบบ nested

## Syntax

```excel
Table.ExpandRecordColumn(table as table, column as text, fieldNames as list, optional newColumnNames as nullable list) as table
```

**Variant**

```excel
Table.ExpandRecordColumn(table, "columnName", {"field1", "field2"})
```

ขยาย Record column โดยใช้ชื่อฟิลด์เดิมเป็นชื่อคอลัมน์ใหม่

**Variant**

```excel
Table.ExpandRecordColumn(table, "columnName", {"field1"}, {"NewName1"})
```

ขยาย Record และกำหนดชื่อคอลัมน์ใหม่เพื่อป้องกันชื่อซ้ำ

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางข้อมูลที่มีคอลัมน์ประเภท Record ที่ต้องการขยาย |
| column | Yes | text |  | ชื่อคอลัมน์ที่เก็บ Record values ที่ต้องการขยาย |
| fieldNames | Yes | list |  | List ของชื่อฟิลด์ที่ต้องการดึงออกมาจาก Record เช่น {"name", "age", "email"} |
| newColumnNames | No | nullable list | null | List ของชื่อคอลัมน์ใหม่ที่ต้องการใช้แทนชื่อฟิลด์เดิม เพื่อป้องกันชื่อซ้ำกับคอลัมน์อื่นในตาราง |

## เคสการใช้งาน

### ขยายข้อมูลจาก API Response

เมื่อเรียก API แล้วได้ JSON response ที่มีโครงสร้างซ้อนกัน ใช้ฟังก์ชันนี้เพื่อขยาย Record fields ออกเป็นคอลัมน์แยกเพื่อความสะดวกในการวิเคราะห์

_เหมาะกับ:_ api-data-transformation

### แปลง Nested JSON เป็น Flat Table

แปลงข้อมูล JSON ที่มีโครงสร้างซ้อนกันหลายชั้นให้เป็นตารางแบน (flat table) เพื่อให้ง่ายต่อการประมวลผลและการสร้างรายงาน

_เหมาะกับ:_ data-normalization

### ดึงข้อมูลจาก Nested Columns

ดึงฟิลด์ที่ต้องการออกจากคอลัมน์ที่เก็บข้อมูลหลายฟิลด์รวมกัน เช่น คอลัมน์ Address ที่มี street, city, zipcode

_เหมาะกับ:_ field-extraction

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ขยาย Record Column พื้นฐาน

```excel
let
    Source = Table.FromRecords({
        [
            a = [aa = 1, bb = 2, cc = 3],
            b = 2
        ]
    }),
    Expanded = Table.ExpandRecordColumn(Source, "a", {"aa", "bb", "cc"})
in
    Expanded
```

**ผลลัพธ์:** `Table: {[aa=1, bb=2, cc=3, b=2]}`

ขยายคอลัมน์ a ซึ่งเป็น Record ที่มี 3 ฟิลด์ (aa, bb, cc) ออกเป็น 3 คอลัมน์แยกกัน คอลัมน์ b ยังคงอยู่ในตารางเหมือนเดิม

### 2. ตัวอย่างที่ 2: ขยายพร้อมเปลี่ยนชื่อคอลัมน์

```excel
let
    Source = Table.FromRecords({
        [
            ID = 1,
            Details = [Name = "John", Age = 30, City = "Bangkok"]
        ],
        [
            ID = 2,
            Details = [Name = "Jane", Age = 25, City = "Chiang Mai"]
        ]
    }),
    Expanded = Table.ExpandRecordColumn(
        Source,
        "Details",
        {"Name", "Age", "City"},
        {"CustomerName", "CustomerAge", "CustomerCity"}
    )
in
    Expanded
```

**ผลลัพธ์:** `Table: {[ID=1, CustomerName="John", CustomerAge=30, CustomerCity="Bangkok"], [ID=2, ...]}`

ขยาย Record column Details และเปลี่ยนชื่อคอลัมน์ใหม่เป็น CustomerName, CustomerAge, CustomerCity เพื่อให้ชัดเจนและป้องกันชื่อซ้ำ

### 3. ตัวอย่างที่ 3: ขยายเฉพาะฟิลด์ที่ต้องการ

```excel
let
    Source = Table.FromRecords({
        [
            OrderID = 101,
            Customer = [Name = "Bob", Email = "bob@email.com", Phone = "123-4567"]
        ]
    }),
    Expanded = Table.ExpandRecordColumn(
        Source,
        "Customer",
        {"Name", "Email"}
    )
in
    Expanded
```

**ผลลัพธ์:** `Table: {[OrderID=101, Name="Bob", Email="bob@email.com"]}`

ขยายเฉพาะ Name และ Email จาก Customer record โดยไม่เอา Phone field ออกมา เหมาะสำหรับเลือกข้อมูลที่จำเป็นเท่านั้น

### 4. ตัวอย่างที่ 4: ขยายหลาย Records ในตาราง

```excel
let
    Source = Table.FromRecords({
        [ID = 1, Data = [X = 10, Y = 20]],
        [ID = 2, Data = [X = 30, Y = 40]],
        [ID = 3, Data = [X = 50, Y = 60]]
    }),
    Expanded = Table.ExpandRecordColumn(Source, "Data", {"X", "Y"})
in
    Expanded
```

**ผลลัพธ์:** `Table: {[ID=1, X=10, Y=20], [ID=2, X=30, Y=40], [ID=3, X=50, Y=60]}`

ขยาย Record ในทุกแถวของตาราง ทำให้แต่ละแถวมีคอลัมน์ X และ Y แยกจาก Data record pattern นี้ใช้บ่อยในการทำงานกับข้อมูลจาก API

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

ฟังก์ชันนี้ใช้บ่อยมากเมื่อทำงานกับข้อมูลจาก API หรือ JSON files ที่มีโครงสร้างแบบ nested เพราะช่วยแปลงข้อมูลที่ซับซ้อนให้เป็นตารางแบนที่ง่ายต่อการวิเคราะห์ ควรใช้ร่วมกับ Table.ExpandTableColumn สำหรับข้อมูลที่ซ้อนกันหลายระดับ

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

**Q: ถ้าระบุฟิลด์ที่ไม่มีใน Record จะเกิดอะไรขึ้น?**

จะเกิด error ทันที ต้องตรวจสอบให้แน่ใจว่าชื่อฟิลด์ใน fieldNames parameter ตรงกับฟิลด์ที่มีอยู่จริงใน Record หรือใช้ try...otherwise เพื่อจัดการ error

**Q: จำเป็นต้องขยายทุกฟิลด์ใน Record หรือไม่?**

ไม่จำเป็น สามารถเลือกขยายเฉพาะฟิลด์ที่ต้องการได้โดยระบุเฉพาะชื่อฟิลด์นั้นใน fieldNames parameter ฟิลด์อื่นที่ไม่ระบุจะไม่ถูกขยายออกมา

**Q: ควรใช้ newColumnNames เมื่อไร?**

ใช้เมื่อชื่อฟิลด์ใน Record ซ้ำกับชื่อคอลัมน์อื่นที่มีอยู่แล้วในตาราง หรือเมื่อต้องการให้ชื่อคอลัมน์ใหม่มีความหมายชัดเจนกว่า เช่น เปลี่ยนจาก "Name" เป็น "CustomerName"

**Q: ต่างจาก Table.ExpandTableColumn อย่างไร?**

Table.ExpandRecordColumn ใช้ขยาย Record (single row of fields) ส่วน Table.ExpandTableColumn ใช้ขยาย Table (multiple rows) ถ้าคอลัมน์เก็บข้อมูลเป็น table ให้ใช้ Table.ExpandTableColumn แทน

**Q: สามารถขยาย Record ที่ซ้อนกันหลายชั้นได้ไหม?**

ได้ แต่ต้องขยายทีละชั้น เช่น ขยายชั้นแรกก่อน จะได้คอลัมน์ที่เป็น Record ชั้นที่สอง จากนั้นใช้ Table.ExpandRecordColumn อีกครั้งเพื่อขยายชั้นที่สอง

## ฟังก์ชันที่เกี่ยวข้อง

- [Table.ExpandTableColumn – แตกข้อมูลจากคอลัมน์ตารางที่ซ้อนกัน](https://www.thepexcel.com/functions/power-query/table-functions/table-expandtablecolumn/)
- [Table.AddColumn – เพิ่มคอลัมน์ใหม่ด้วย Calculated Values](https://www.thepexcel.com/functions/power-query/table-functions/table-addcolumn/)
- [Record.Field – ดึงค่า Field จาก Record](https://www.thepexcel.com/functions/power-query/record-functions/record-field/)
- [Table.FromRecords – สร้างตารางจากรายการ Record](https://www.thepexcel.com/functions/power-query/table-functions/table-fromrecords/)
- [Json.Document – แปลง JSON Text เป็น Power Query Record](https://www.thepexcel.com/functions/power-query/accessing-data-functions/json-document/)

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

- [Microsoft Learn - Table.ExpandRecordColumn Official Documentation](https://learn.microsoft.com/en-us/powerquery-m/table-expandrecordcolumn) _(documentation)_
- [Microsoft Learn - Working with Records in Power Query](https://learn.microsoft.com/en-us/power-query/) _(documentation)_
- [PowerQuery.how - Table.ExpandRecordColumn Guide](https://powerquery.how/table-expandrecordcolumn/) _(guide)_

---

_Source: [https://www.thepexcel.com/functions/power-query/table-functions/table-expandrecordcolumn-3/](https://www.thepexcel.com/functions/power-query/table-functions/table-expandrecordcolumn-3/)_
