---
title: Table.ToRecords – แปลงตารางเป็น List ของ Record
url: https://www.thepexcel.com/functions/power-query/table-functions/table-torecords/
type: function-explainer
program: Power Query
syntax: Table.ToRecords(table as table) as list
date: 2025-12-03
updated: 2025-12-23
scores:
  popularity: 6
  difficulty: 4
  usefulness: 7
---

# Table.ToRecords – แปลงตารางเป็น List ของ Record

> Table.ToRecords แปลงตารางให้เป็น List โดยแต่ละแถวกลายเป็น Record พร้อมชื่อคอลัมน์เป็น Field Name ทำใ

## คำอธิบาย

Table.ToRecords แปลงตารางให้เป็น List โดยแต่ละแถวกลายเป็น Record พร้อมชื่อคอลัมน์เป็น Field Name ทำให้สะดวกในการวนลูปแบบมีโครงสร้าง

## Syntax

```excel
Table.ToRecords(table as table) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางต้นทางที่ต้องการแปลงเป็น List ของ Record |

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

### ประมวลผลข้อมูลทีละแถว

ใช้ List.Transform ร่วมกับ Table.ToRecords เพื่อประมวลผลข้อมูลแต่ละแถวด้วย Logic ที่ซับซ้อน

### การสร้างข้อมูล JSON

โครงสร้าง Record ที่ได้จากฟังก์ชันนี้ใกล้เคียงกับ Object ใน JSON ทำให้ง่ายต่อการ Export เป็น JSON

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: แปลงตารางพื้นฐาน

```excel
let
    SourceTable = Table.FromRecords({
        [ProductID = 1, ProductName = "Laptop", Price = 25000],
        [ProductID = 2, ProductName = "Mouse", Price = 500],
        [ProductID = 3, ProductName = "Keyboard", Price = 2000]
    }),
    AsRecordList = Table.ToRecords(SourceTable)
in
    AsRecordList
```

**ผลลัพธ์:** `{
    [ProductID = 1, ProductName = "Laptop", Price = 25000],
    [ProductID = 2, ProductName = "Mouse", Price = 500],
    [ProductID = 3, ProductName = "Keyboard", Price = 2000]
}`

ตาราง 3 แถว ถูกแปลงเป็น List ของ 3 Records โดยแต่ละ Record มี Field ProductID, ProductName, Price ตามชื่อคอลัมน์เดิม

### 2. ตัวอย่างที่ 2: ใช้ร่วมกับ List.Transform เพื่อคำนวณแต่ละแถว

```excel
let
    Source = Table.FromRecords({
        [Quantity = 10, UnitPrice = 100],
        [Quantity = 5, UnitPrice = 200],
        [Quantity = 3, UnitPrice = 500]
    }),
    RecordList = Table.ToRecords(Source),
    WithTotal = List.Transform(RecordList, each _ & [Total = [Quantity] * [UnitPrice]])
in
    WithTotal
```

**ผลลัพธ์:** `{
    [Quantity = 10, UnitPrice = 100, Total = 1000],
    [Quantity = 5, UnitPrice = 200, Total = 1000],
    [Quantity = 3, UnitPrice = 500, Total = 1500]
}`

ใช้ Table.ToRecords แปลงเป็น List แล้วทำ List.Transform เพื่อเพิ่ม Field Total ให้แต่ละ Record ด้วยการคูณ Quantity × UnitPrice

### 3. ตัวอย่างที่ 3: แยกเอา Field ที่ต้องการจาก Record List

```excel
let
    Source = Table.FromRecords({
        [Name = "Alice", Email = "alice@example.com", Department = "Sales"],
        [Name = "Bob", Email = "bob@example.com", Department = "IT"]
    }),
    RecordList = Table.ToRecords(Source),
    NameAndEmail = List.Transform(RecordList, each [Name = [Name], Email = [Email]])
in
    NameAndEmail
```

**ผลลัพธ์:** `{
    [Name = "Alice", Email = "alice@example.com"],
    [Name = "Bob", Email = "bob@example.com"]
}`

ใช้ Table.ToRecords + List.Transform ทำให้เราเลือกเฉพาะ Field Name และ Email ที่ต้องการ โดยตัดทิ้ง Department

### 4. ตัวอย่างที่ 4: ใช้ List.Select เพื่อกรองข้อมูลจาก Record List

```excel
let
    Source = Table.FromRecords({
        [StudentName = "John", Score = 85],
        [StudentName = "Jane", Score = 92],
        [StudentName = "Mike", Score = 78],
        [StudentName = "Sarah", Score = 88]
    }),
    RecordList = Table.ToRecords(Source),
    HighScores = List.Select(RecordList, each [Score] >= 85)
in
    HighScores
```

**ผลลัพธ์:** `{
    [StudentName = "John", Score = 85],
    [StudentName = "Jane", Score = 92],
    [StudentName = "Sarah", Score = 88]
}`

แปลงตารางเป็น Record List แล้วใช้ List.Select เพื่อกรองเฉพาะ Record ที่ Score ≥ 85 ออกมา

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

- ใช้ Table.ToRecords เมื่อต้องการประมวลผลแบบ Row-by-Row ด้วย List.Transform เพราะมันทำให้เข้าถึง Field ด้วยชื่อแทนหมายเลขคอลัมน์

- รวม Table.ToRecords + List.Transform ได้ผลดี เช่นเพิ่ม Field ใหม่, คำนวณค่า, หรือเปลี่ยนแปลง Field ตามเงื่อนไข

- ถ้าต้องการกลับมาเป็นตารางอีกครั้ง ใช้ Table.FromRecords(your_record_list) เลยนะครับ

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

**Q: ผลลัพธ์ที่ได้เป็น List ของ Record ต่างจาก Table อย่างไร?**

List ของ Record ไม่มีชื่อคอลัมน์แสดง แต่ข้อมูลแต่ละ Record ยังมี Field Name ที่สามารถเข้าถึงแบบ [FieldName] ได้อยู่ ส่วนตาราง (Table) มีโครงสร้างแสดงชื่อคอลัมน์ชัดเจน ถ้าต้องการแสดงผลลัพธ์เป็นตารางอีกครั้งก็ใช้ Table.FromRecords กลับไป

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

Table.ToRecords คืน List ของ Record (มีชื่อ Field) ส่วน Table.ToRows คืน List ของ List (เป็นเพียงค่าโดยไม่มีชื่อคอลัมน์) เมื่อใช้ Table.ToRows ต้องจำว่าสมาชิกลำดับที่ 1 คือคอลัมน์แรก ลำดับที่ 2 คือคอลัมน์ที่สอง เป็นต้น แต่ Table.ToRecords ทำให้สะดวกกว่าเพราะเข้าถึงแบบชื่อ

**Q: เมื่อไหร่ที่ต้องใช้ Table.ToRecords?**

ใช้เมื่อต้องการประมวลผลแต่ละแถวแบบ Custom Logic ที่ซับซ้อน เช่นคำนวณค่า, สร้าง Field ใหม่, เปลี่ยนชื่อ Field, หรือกรองข้อมูลแบบมีเงื่อนไขที่ต้องเข้าถึง Field หลายตัว เมื่อใช้ร่วมกับ List.Transform, List.Select, List.Select ทำให้สะดวกมากครับ

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

- [Microsoft Learn: Table.ToRecords](https://learn.microsoft.com/en-us/powerquery-m/table-torecords) _(official)_
- [Microsoft Learn: Table.FromRecords](https://learn.microsoft.com/en-us/powerquery-m/table-fromrecords) _(official)_
- [Microsoft Learn: List.Transform](https://learn.microsoft.com/en-us/powerquery-m/list-transform) _(official)_
- [Microsoft Learn: List.Select](https://learn.microsoft.com/en-us/powerquery-m/list-select) _(official)_

---

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