---
title: Table.Split – แบ่งตารางเป็น Page
url: https://www.thepexcel.com/functions/power-query/table-functions/table-split/
type: function-explainer
program: Power Query
syntax: "Table.Split(table as table, pageSize as number) as list"
date: 2025-12-06
updated: 2025-12-24
scores:
  popularity: 5
  difficulty: 4
  usefulness: 6
---

# Table.Split – แบ่งตารางเป็น Page

> แบ่งตารางออกเป็นรายการของตารางย่อยตามจำนวนแถวที่กำหนด เหมาะสำหรับ Pagination และ Batch Processing

## คำอธิบาย

แบ่งตารางออกเป็นรายการของตารางย่อยตามจำนวนแถวที่กำหนด เหมาะสำหรับ Pagination และ Batch Processing

## Syntax

```excel
Table.Split(table as table, pageSize as number) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางที่ต้องการแบ่ง |
| pageSize | Yes | number |  | จำนวนแถวต่อหนึ่งส่วน (Page Size) ต้องเป็นตัวเลขบวก |

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

### Pagination

Pagination

### Batch Processing

Batch Processing

## ตัวอย่าง

### 1. แบ่งทีละ 2 แถว

```excel
let
    Source = #table({"ID"}, {{1}, {2}, {3}, {4}, {5}}),
    Split = Table.Split(Source, 2)
in
    Split
```

**ผลลัพธ์:** `List of 3 Tables: {2 rows}, {2 rows}, {1 row}`

แบ่งข้อมูล 5 แถวออกเป็นชุดละ 2 แถว จะได้ 3 ตาราง (2, 2, 1 แถว) - ตารางสุดท้ายเหลือแถวน้อยเพราะหารไม่ลงตัว

### 2. Batch Processing (ประมวลผลทีละชุด)

```excel
let
    Source = #table({"Value"}, List.Zip({1..100})),
    // แบ่งเป็นชุดละ 10 แถว
    Batches = Table.Split(Source, 10),
    // นำไปประมวลผล (เช่น: นับจำนวนแถว)
    RowCounts = List.Transform(Batches, each Table.RowCount(_))
in
    RowCounts
```

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

แบ่งข้อมูล 100 แถว เป็น 10 ชุด (ชุดละ 10 แถว) แล้วนำไปประมวลผลต่อด้วย List.Transform

### 3. แบ่งข้อมูลเพื่อส่ง API

```excel
let
    CustomerData = Table.FromRecords({
        [ID=1, Name="Alice"], [ID=2, Name="Bob"], [ID=3, Name="Charlie"],
        [ID=4, Name="David"], [ID=5, Name="Eve"], [ID=6, Name="Frank"]
    }),
    // API รับข้อมูลได้ทีละ 2 รายการ
    Pages = Table.Split(CustomerData, 2),
    // ส่งข้อมูลทีละหน้า (ตัวอย่าง)
    BatchText = List.Transform(Pages, each "Batch: " & Text.From(Table.RowCount(_)) & " rows")
in
    BatchText
```

**ผลลัพธ์:** `{"Batch: 2 rows", "Batch: 2 rows", "Batch: 2 rows"}`

ตัวอย่างการแบ่งข้อมูลเพื่อส่ง API ที่มีข้อจำกัดจำนวนรายการ - จะส่ง 3 ครั้ง ครั้งละ 2 รายการ

### 4. แบ่งข้อมูลแล้วแปลงเป็น Table List

```excel
let
    Source = Table.FromList(
        {"A", "B", "C", "D", "E", "F", "G"},
        Splitter.SplitByNothing(),
        {"Letter"}
    ),
    SplitPages = Table.Split(Source, 3),
    // หากต้องการ List of Lists เพื่อจัดการต่อไป
    AsList = List.Transform(SplitPages, each Table.ToRows(_))
in
    AsList
```

**ผลลัพธ์:** `List of lists: {{"A"}, {"B"}, {"C"}}, {{"D"}, {"E"}, {"F"}}, {{"G"}}`

แบ่งตารางแล้วแปลง rows เป็น nested lists สำหรับการประมวลผลที่ต้องการ row-by-row structure

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

- ใช้ List.Transform กับ Table.Split เพื่อประมวลผล batch ต่างๆ เช่น List.Transform(Pages, each CallApi(_))

- ถ้าตั้งค่า pageSize ใหญ่เกินไป จะได้ batches น้อยแต่ size ใหญ่ - ถ้าเล็กเกินไป จะได้ batches เยอะ ต้องปรับสมดุล

- สามารถคำนวณ pageSize จากจำนวนแถวทั้งหมด เช่น: Table.Split(Source, Number.RoundUp(Table.RowCount(Source) / 10))

- ถ้าต้องติดตามว่า batch ไหน ให้เพิ่ม index ด้วย List.Transform(...) ร่วมกับ List.Numbers()

- Table.Split เก็บเฉพาะข้อมูลแถว - ข้อมูล metadata (column names) ยังอยู่ในแต่ละ sub-table ทุกตัว

- หากต้องการผลลัพธ์เป็น List of Lists (ไม่ใช่ List of Tables) ให้ใช้ List.Transform(Split, each Table.ToRows(_))

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

**Q: ถ้า pageSize มากกว่าจำนวนแถวทั้งหมด จะเกิดอะไร?**

จะส่งกลับ list ที่มีตารางเดียว (ตารางต้นฉบับ) เช่น ถ้าตารางมี 5 แถว แต่กำหนด pageSize=100 ผลลัพธ์จะเป็น list ที่มีตารางเดียวที่มี 5 แถว

**Q: ถ้า pageSize เป็น 0 หรือจำนวนลบ จะเกิดอะไร?**

จะเกิด error: "Expression.Error: The value of pageSize parameter of Table.Split must be greater than 0" - ต้องใช้ pageSize ที่เป็นตัวเลขบวก

**Q: Table.Split เหมาะสำหรับตารางขนาดเท่าไหร่?**

สามารถใช้กับตารางขนาดใดก็ได้ แต่มีประโยชน์มากโดยเฉพาะตารางที่มีแถวนับพันหรือนับหมื่น เพราะช่วยให้ประมวลผล batch ได้ง่ายและหลีกเลี่ยงโอเวอร์โหลด

**Q: ความต่างระหว่าง Table.Split กับ Table.Group คืออะไร?**

Table.Split แบ่งตามจำนวนแถว (ตำแหน่ง) ส่วน Table.Group แบ่งตามค่าในคอลัมน์ (หมวดหมู่) - Table.Split สำหรับ pagination, Table.Group สำหรับ grouping ตามข้อมูล

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

- [Table.Partition – แบ่งตารางเป็นส่วนๆ](https://www.thepexcel.com/functions/power-query/table-functions/table-partition/)
- [Table.Group – จัดกลุ่มและสรุปผลข้อมูล (Group By)](https://www.thepexcel.com/functions/power-query/table-functions/table-group/)

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

- [Microsoft Docs - Table.Split](https://learn.microsoft.com/en-us/powerquery-m/table-split) _(official)_
- [PowerQuery.how](https://powerquery.how/table-split/) _(article)_

---

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