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

# Table.ToRows – แปลงตารางเป็น List ของ List (รายแถว)

> Table.ToRows แปลงตารางให้เป็น List ของ List โดยแต่ละ List ย่อยแทนข้อมูล 1 แถว ไม่มีชื่อคอลัมน์ เหมาะ

## คำอธิบาย

Table.ToRows แปลงตารางให้เป็น List ของ List โดยแต่ละ List ย่อยแทนข้อมูล 1 แถว ไม่มีชื่อคอลัมน์ เหมาะสำหรับส่งออกข้อมูลเป็น JSON/CSV หรือประมวลผลแถวโดยไม่สนใจชื่อฟิลด์

## Syntax

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

## Arguments

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

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

### สร้างไฟล์ CSV จากตาราง

ใช้ Text.Combine ร่วมกับ Table.ToRows เพื่อแปลงข้อมูลในตารางให้เป็นรูปแบบ CSV

### ประมวลผลข้อมูลทีละแถวโดยไม่สนใจชื่อคอลัมน์

เหมาะสำหรับกรณีที่ต้องการประมวลผลข้อมูลแบบ Element-by-Element หรือเมื่อชื่อคอลัมน์ไม่สำคัญ

## ตัวอย่าง

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

```excel
let
    SampleTable = Table.FromRecords(
        {
            [ID = 1, Name = "Bob", Phone = "123-4567"],
            [ID = 2, Name = "Jim", Phone = "987-6543"],
            [ID = 3, Name = "Paul", Phone = "543-7890"]
        }
    ),
    Result = Table.ToRows(SampleTable)
in
    Result
```

**ผลลัพธ์:** `{{1, "Bob", "123-4567"}, {2, "Jim", "987-6543"}, {3, "Paul", "543-7890"}}`

ตาราง 3 แถว 3 คอลัมน์ ถูกแปลงเป็น List ของ 3 Lists ย่อย แต่ละ List ย่อยประกอบด้วยค่าจากแถวนั้นเท่านั้น ไม่มี Field Names

### 2. ตัวอย่างจริง: ส่งออก CSV

```excel
let
    Source = Table.FromRecords(
        {
            [OrderID = "001", Amount = 1500],
            [OrderID = "002", Amount = 2300],
            [OrderID = "003", Amount = 800]
        }
    ),
    AsRows = Table.ToRows(Source),
    CsvFormat = Text.Combine(
        List.Transform(
            AsRows,
            each Text.Combine(List.Transform(_, Text.From), ",")
        ),
        "#(lf)"
    )
in
    CsvFormat
```

**ผลลัพธ์:** `"001,1500\n002,2300\n003,800"`

แปลงตารางเป็น List of Lists แล้วจึง combine ข้อมูลให้เป็น CSV format ที่มี comma delimiter และ line feed

### 3. เปรียบเทียบ Table.ToRows vs Table.ToRecords

```excel
let
    Data = Table.FromRecords({[ID = 1, Status = "Active"]}),
    Rows = Table.ToRows(Data),
    Records = Table.ToRecords(Data)
in
    {Rows, Records}
```

**ผลลัพธ์:** `{{1, "Active"}, {[ID = 1, Status = "Active"]}}`

Table.ToRows ⟶ {{1, "Active"}} (List ของ List) | Table.ToRecords ⟶ {[ID = 1, Status = "Active"]} (List ของ Record ที่มี Field Names)

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

- ใช้ Table.ToRows เมื่อต้องการโครงสร้างง่ายๆ หากต้อง Field Names ให้ใช้ Table.ToRecords

- ลำดับคอลัมน์ตรงกับลำดับค่าในแต่ละ List ย่อย ตรวจสอบให้แน่ใจ

- สามารถ combine กับ List.Transform เพื่อประมวลผลแต่ละแถว

- เหมาะสำหรับแปลงเป็น CSV, JSON arrays, หรือส่งข้อมูลไป API

- ถ้ากำลังทำงานกับข้อมูลจำนวนมาก ให้พิจารณา performance เนื่องจาก nested list อาจใช้เนื้อที่หน่วยความจำมาก

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

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

Table.ToRows คืน List ของ List (เช่น {{1, 2}, {3, 4}}) โดยไม่มีชื่อคอลัมน์ ส่วน Table.ToRecords คืน List ของ Record (เช่น {[A=1, B=2], [A=3, B=4]}) ที่มี Field Names หากคุณต้องการชื่อคอลัมน์เพื่อการประมวลผลต่อไป ให้ใช้ Table.ToRecords แต่ถ้าแค่ต้องการค่าข้อมูลแบบง่ายๆ ให้ใช้ Table.ToRows

**Q: ใช้ Table.ToRows ตอนไหน?**

ใช้เวลาต้องการ: (1) ส่งออกเป็น CSV/JSON array format, (2) ประมวลผลแถวโดยไม่จำเป็นต้องรู้ชื่อคอลัมน์, (3) ส่งข้อมูลไปยัง API ที่ต้องการ array-of-arrays, (4) สร้าง List แบบง่ายๆ เพื่อใช้งานต่อไป

**Q: ค่าจากแถวจะเรียงตามลำดับไหน?**

ค่าจะเรียงตามลำดับของคอลัมน์ในตารางจากซ้ายไปขวา เช่น ถ้าตารางมี คอลัมน์ A, B, C ลำดับจะเป็น {valueA, valueB, valueC}

**Q: ถ้าตารางไม่มีแถวเลยจะเกิดอะไร?**

จะคืน List ว่าง {} (empty list) ไม่ใช่ error

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

- [List.Transform – แปลงค่าในลิสต์แต่ละตัว](https://www.thepexcel.com/functions/power-query/list-functions/list-transform/)
- [Record.ToList – แปลง Record เป็น List ของค่าข้อมูล](https://www.thepexcel.com/functions/power-query/record-functions/record-tolist/)
- [Table.ToColumns – แปลงตารางเป็น List ของ List (รายคอลัมน์)](https://www.thepexcel.com/functions/power-query/table-functions/table-tocolumns/)
- [Table.ToRecords – แปลงตารางเป็น List ของ Record](https://www.thepexcel.com/functions/power-query/table-functions/table-torecords/)

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

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

---

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