---
title: Table.TransformRows – แปลงแต่ละแถวของตารางเป็นรายการ
url: https://www.thepexcel.com/functions/power-query/table-functions/table-transformrows/
type: function-explainer
program: Power Query
syntax: "Table.TransformRows(table as table, transform as function) as list"
date: 2025-12-06
updated: 2025-12-23
scores:
  popularity: 5
  difficulty: 6
  usefulness: 6
---

# Table.TransformRows – แปลงแต่ละแถวของตารางเป็นรายการ

> Table.TransformRows ใช้สำหรับประมวลผลแต่ละแถวของตารางด้วยฟังก์ชนที่กำหนด แล้วคืนผลลัพธ์กลับมาเป็น Li

## คำอธิบาย

Table.TransformRows ใช้สำหรับประมวลผลแต่ละแถวของตารางด้วยฟังก์ชนที่กำหนด แล้วคืนผลลัพธ์กลับมาเป็น List (ไม่ใช่ Table)

## Syntax

```excel
Table.TransformRows(table as table, transform as function) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางที่ต้องการประมวลผลแต่ละแถว |
| transform | Yes | function |  | ฟังก์ชันที่ใช้แปลงข้อมูลแต่ละแถว สามารถใช้ each [Column] หรือ (row) => expression ได้ |

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

### สร้าง List ใหม่จากการคำนวณค่าในแต่ละแถว

สร้าง List ใหม่จากการคำนวณค่าในแต่ละแถว

### แปลงโครงสร้างข้อมูลจากตารางเป็น List ของ Record หรือค่าอื่นๆ

แปลงโครงสร้างข้อมูลจากตารางเป็น List ของ Record หรือค่าอื่นๆ

### เตรียมข้อมูลสำหรับการประมวลผลด้วย List functions

เตรียมข้อมูลสำหรับการประมวลผลด้วย List functions

## ตัวอย่าง

### 1. ดึงค่าจากคอลัมน์เดียวเป็น List

```excel
let
    Sales = Table.FromRecords({
        [OrderID = 1, Amount = 1500],
        [OrderID = 2, Amount = 2300],
        [OrderID = 3, Amount = 800]
    }),
    AmountList = Table.TransformRows(Sales, each [Amount])
in
    AmountList
// Result: {1500, 2300, 800}
```

**ผลลัพธ์:** `{1500, 2300, 800}`

ใช้ each [Amount] เพื่อดึงค่าจากคอลัมน์ Amount จากแต่ละแถว ผลลัพธ์คือ List ของตัวเลข

### 2. คำนวณค่าจากหลายคอลัมน์

```excel
let
    Invoice = Table.FromRecords({
        [Qty = 5, Price = 100],
        [Qty = 3, Price = 200],
        [Qty = 10, Price = 50]
    }),
    Totals = Table.TransformRows(Invoice, each [Qty] * [Price])
in
    Totals
// Result: {500, 600, 500}
```

**ผลลัพธ์:** `{500, 600, 500}`

สำหรับแต่ละแถว คำนวณ Qty * Price แล้วเก็บผลลัพธ์ไว้ใน List

### 3. แปลงแต่ละแถวเป็น Record ใหม่ที่มีคอลัมน์เพิ่มเติม

```excel
let
    Employee = Table.FromRecords({
        [ID = 1, Name = "Alice", Salary = 50000],
        [ID = 2, Name = "Bob", Salary = 55000]
    }),
    WithBonus = Table.TransformRows(
        Employee,
        (row) => [
            ID = row[ID],
            Name = row[Name],
            Annual = row[Salary] * 12,
            Bonus = Number.ToText(row[Salary] * 0.1)
        ]
    )
in
    WithBonus
// Result: {[ID = 1, Name = "Alice", Annual = 600000, Bonus = "5000"], [ID = 2, Name = "Bob", Annual = 660000, Bonus = "5500"]}
```

**ผลลัพธ์:** `{[ID = 1, Name = "Alice", Annual = 600000, Bonus = "5000"], [ID = 2, Name = "Bob", Annual = 660000, Bonus = "5500"]}`

ใช้ (row) => [...] เพื่อสร้าง Record ใหม่สำหรับแต่ละแถว มีการคำนวณเงินเดือนประจำปี และโบนัส

### 4. แปลงเป็น Text List พร้อมการฟอร์แมต

```excel
let
    Products = Table.FromRecords({
        [ProductName = "Laptop", Category = "Electronics"],
        [ProductName = "Mouse", Category = "Electronics"],
        [ProductName = "Desk", Category = "Furniture"]
    }),
    Labels = Table.TransformRows(
        Products,
        each [Category] & ": " & [ProductName]
    )
in
    Labels
// Result: {"Electronics: Laptop", "Electronics: Mouse", "Furniture: Desk"}
```

**ผลลัพธ์:** `{\"Electronics: Laptop\", \"Electronics: Mouse\", \"Furniture: Desk\"}`

รวมค่าจากหลายคอลัมน์และฟอร์แมตเป็นข้อความเดียว

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

- ใช้ each [Column] สำหรับการแปลงแบบง่ายๆ เช่น ดึงคอลัมน์เดียวหรือบวกสองคอลัมน์

- ใช้ (row) => expression สำหรับการแปลงที่ซับซ้อน เช่น สร้าง Record ใหม่หรือต้อง Type Annotation

- หากต้องการแปลง List of Records กลับเป็น Table ให้ใช้ List.ToTable() หลังจากได้ผลลัพธ์จาก Table.TransformRows

- ถ้าต้องแยกหลายคอลัมน์เป็น Nested List ลองใช้ Table.ToRows() แทน จะได้ List of Lists

- Table.TransformRows สามารถใช้ Record.TransformFields() ข้างในเพื่อแปลงเฉพาะฟิลด์บางตัว ของแต่ละแถวได้

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

**Q: Table.TransformRows กับ Table.AddColumn ต่างกันตรงไหน?**

Table.AddColumn สร้างคอลัมน์ใหม่แล้วคืน Table กลับมา ส่วน Table.TransformRows แปลงแต่ละแถวแล้วคืน List ไม่ใช่ Table ใช้ Table.TransformRows ตอนต้อง Export ข้อมูล API หรือประมวลผลแบบแถวต่อแถว

**Q: Table.TransformRows กับ List.Transform ต่างกันตรงไหน?**

Table.TransformRows ทำงานกับ Table ได้ใช้ [ColumnName] โดยตรง ส่วน List.Transform ทำงานกับ List และ (item) => expression List.Transform เหมาะสำหรับข้อมูลที่เป็น List อยู่แล้ว ส่วน Table.TransformRows เหมาะสำหรับ Table

**Q: Transform function ต้องคืน Type เดียวกันหรือ?**

ไม่จำเป็น Transform function สามารถคืน type ต่างๆ ได้ (text, number, record, list) ตัวอย่างเช่น each [Amount] คืน number ส่วน each [Name] & ":" & [ID] คืน text ได้

**Q: ถ้าตารางมี 100,000 แถว ดำเนินการช้าไหม?**

ความเร็วขึ้นอยู่กับความซับซ้อนของฟังก์ชัน transform ถ้าเรียบง่าย (แค่ [Column] หรือบวกลบ) ไม่ช้า แต่ถ้า transform มี lookup หรือเรียก API ในแต่ละแถว จะช้ามากๆ ลอง Table.AddColumn เพราะบาง transform สามารถใช้ได้ทั้งสองฟังก์ชัน

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

- [Microsoft Learn: Table.TransformRows](https://learn.microsoft.com/en-us/powerquery-m/table-transformrows) _(official)_
- [Power Query M Function Reference](https://learn.microsoft.com/en-us/powerquery-m/) _(official)_

---

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