---
title: Text.Split – แยกข้อความตามตัวคั่นที่กำหนด
url: https://www.thepexcel.com/functions/power-query/text-functions/text-split/
type: function-explainer
program: Power Query
syntax: "Text.Split(text as text, separator as text) as list"
date: 2025-12-03
updated: 2025-12-20
scores:
  popularity: 8
  difficulty: 3
  usefulness: 8
---

# Text.Split – แยกข้อความตามตัวคั่นที่กำหนด

> Text.Split(text, separator) ใช้แยกข้อความเป็น List โดยอิงตามตัวคั่น (delimiter) ที่ระบุ สามารถใช้ตัว

## คำอธิบาย

Text.Split(text, separator) ใช้แยกข้อความเป็น List โดยอิงตามตัวคั่น (delimiter) ที่ระบุ สามารถใช้ตัวคั่นเพียงตัวเดียวหรือหลายตัวอักษร เช่น "|" หรือ ", the " ผลลัพธ์คืนค่าเป็น List ของข้อความ

## Syntax

```excel
Text.Split(text as text, separator as text) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | text |  | ข้อความที่ต้องการแยก (พารามิเตอร์บังคับ) |
| separator | Yes | text |  | ตัวคั่น (delimiter) ใช้สำหรับแยกข้อความ สามารถเป็นตัวอักษรเดียวหรือหลายตัวอักษร เช่น "\|", ",", " AND ", ", the " (พารามิเตอร์บังคับ) |

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

### แยกรหัสสินค้า

ถ้ารหัสสินค้าเป็น "PROD-001-RED" สามารถแยกเป็น "PROD", "001", "RED" ได้

### แยก Tags จากข้อความ

ถ้ามี Field ที่เก็บ Tags หลายๆ คำคั่นด้วยคอมม่า สามารถแยกออกมาเป็น List ของ Tag ได้

### สร้างตารางจากข้อความบรรทัดเดียว

ถ้าข้อมูลในแต่ละคอลัมน์คั่นด้วยตัวอักษรเฉพาะ สามารถใช้ Text.Split เพื่อแยกเป็นคอลัมน์ได้ (ร่วมกับ Table.FromList)

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: แยกข้อความด้วยตัวคั่นเพียงตัวเดียว

```excel
= Text.Split("Name|Address|PhoneNumber", "|")
```

**ผลลัพธ์:** `{"Name", "Address", "PhoneNumber"}`

แยกข้อความ "Name|Address|PhoneNumber" โดยใช้ "|" เป็นตัวคั่น ผลลัพธ์คือ List ที่มี 3 รายการ

### 2. ตัวอย่างที่ 2: แยกข้อความด้วยตัวคั่นหลายตัวอักษร

```excel
= Text.Split("Name, the Customer, the Purchase Date", ", the ")
```

**ผลลัพธ์:** `{"Name", "Customer", "Purchase Date"}`

แยกข้อความโดยใช้ ", the " (สามตัวอักษร) เป็นตัวคั่น ข้อมูล multi-character delimiter จะคำนึงถึงลำดับอักษรและช่องว่างด้วย

### 3. ตัวอย่างที่ 3: แยก CSV ในสูตร let...in

```excel
let
    CSVText = "Apple,Banana,Cherry,Date",
    Fruits = Text.Split(CSVText, ",")
in
    Fruits
```

**ผลลัพธ์:** `{"Apple", "Banana", "Cherry", "Date"}`

ในโครงสร้าง let...in ใช้ Text.Split เพื่อแยก CSV ที่คั่นด้วยเครื่องหมายจุลภาค หลังจากนั้นสามารถนำ List ไปใช้กับ List.Transform หรือ Table.FromRows ได้

### 4. ตัวอย่างที่ 4: แยกข้อมูลและแปลงเป็นตาราง

```excel
let
    Source = "Product-A|100|USD;Product-B|200|USD",
    Rows = Text.Split(Source, ";"),
    SplitColumns = List.Transform(Rows, each Text.Split(_, "|")),
    Table = Table.FromRows(SplitColumns, {"Product", "Price", "Currency"})
in
    Table
```

**ผลลัพธ์:** `ตารางที่มี 2 แถว 3 คอลัมน์:
| Product  | Price | Currency |
|----------|-------|----------|
| Product-A| 100   | USD      |
| Product-B| 200   | USD      |`

ใช้ Text.Split สองครั้ง: ครั้งแรกแยกแต่ละแถวด้วย ";", ครั้งที่สองแยกแต่ละคอลัมน์ด้วย "|" เพื่อสร้างตารางที่มีข้อมูล structured

### 5. ตัวอย่างที่ 5: แยกชื่อเต็มเป็นชื่อและนามสกุล

```excel
let
    FullName = "John Smith",
    Parts = Text.Split(FullName, " "),
    FirstName = Parts{0},
    LastName = Parts{1}
in
    [First = FirstName, Last = LastName]
```

**ผลลัพธ์:** `[First = "John", Last = "Smith"]`

แยกชื่อเต็มด้วยช่องว่าง จากนั้นเข้าถึงรายการแต่ละรายการของ List ด้วย {0} และ {1} โดยใช้ zero-based indexing

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

- ใช้ Text.Split กับ List.Transform เพื่อแยกและทำความสะอาดข้อมูล CSV: List.Transform(Text.Split(data, ","), each Text.Trim(_))

- เมื่อแยกข้อมูลแล้ว ต้อง trim ช่องว่างหากตัวคั่นรอบด้วยช่องว่าง เช่น ", " หรือ " | "

- ใช้ Index {0}, {1}, {2} เพื่อเข้าถึงรายการของ List ที่ได้จาก Text.Split (zero-based indexing)

- ถ้าข้อมูลมีหลายบรรทัด อาจต้องแยกแต่ละบรรทัดก่อน แล้วแยกแต่ละคอลัมน์ เหมือน Example ที่ 4

- ใช้ Text.Split ร่วมกับ Table.FromRows เพื่อแปลง flat text ให้เป็น structured table ได้อย่างมีประสิทธิภาพ

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

**Q: ถ้าตัวคั่นไม่พบในข้อความจะเกิดอะไรขึ้น?**

ถ้าตัวคั่นไม่พบในข้อความ Text.Split จะคืนค่า List ที่มีรายการเดียว ซึ่งก็คือข้อความเดิมทั้งหมด เช่น Text.Split("Hello", "|") จะคืนค่า {"Hello"}

**Q: สามารถใช้ตัวคั่นแบบ regex ได้หรือไม่?**

ไม่ได้ Text.Split ใช้ literal string matching เท่านั้น ถ้าต้องแยกตามรูปแบบ regex ต้องใช้ฟังก์ชัน Splitter.SplitTextByDelimiter() หรือ Text.Replace กับ Table functions อื่นๆ

**Q: ผลลัพธ์ของ Text.Split เป็นประเภท List ใช่หรือไม่?**

ใช่ Text.Split คืนค่า List of text {text, text, ...} สามารถเข้าถึงรายการด้วย {index} หรือใช้ List.Transform เพื่อแปลงแต่ละรายการ

**Q: เมื่อแยกแล้ว ข้อมูลมีช่องว่างข้างหน้าหรือข้างหลังจะหลุดไปหรือไม่?**

ไม่ Text.Split เป็น exact split ถ้าข้อความมีช่องว่างเหลือ เช่น Text.Split("A , B", ",") จะได้ {"A ", " B"} มีช่องว่างอยู่ ต้องใช้ Text.Trim() เพื่อลบช่องว่างออก

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

- [Text.Combine – รวมข้อความหลายรายการเป็นข้อความเดียว](https://www.thepexcel.com/functions/power-query/text-functions/text-combine/)
- [Text.Trim – ตัดอักขระนำหน้าและลงท้าย](https://www.thepexcel.com/functions/power-query/text-functions/text-trim/)
- [Text.Replace – แทนที่ข้อความใน Power Query](https://www.thepexcel.com/functions/power-query/text-functions/text-replace/)
- [List.Transform – แปลงค่าในลิสต์แต่ละตัว](https://www.thepexcel.com/functions/power-query/list-functions/list-transform/)
- [Table.FromRows – สร้างตารางจากรายการแถว](https://www.thepexcel.com/functions/power-query/table-functions/table-fromrows/)

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

- [Microsoft Learn - Text.Split](https://learn.microsoft.com/en-us/powerquery-m/text-split) _(official)_
- [Microsoft Learn - Text.Combine](https://learn.microsoft.com/en-us/powerquery-m/text-combine) _(official)_
- [Microsoft Learn - List.Transform](https://learn.microsoft.com/en-us/powerquery-m/list-transform) _(official)_

---

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