---
title: Text.Length – นับจำนวนตัวอักษรในข้อความ
url: https://www.thepexcel.com/functions/power-query/text-functions/text-length/
type: function-explainer
program: Power Query
syntax: Text.Length(text as nullable text) as nullable number
date: 2025-12-03
updated: 2025-12-24
scores:
  popularity: 7
  difficulty: 2
  usefulness: 7
---

# Text.Length – นับจำนวนตัวอักษรในข้อความ

> Text.Length ใช้นับจำนวนตัวอักษรทั้งหมดในสตริงข้อความ รวมถึงช่องว่างและอักขระพิเศษ ผลลัพธ์คืนค่าเป็นต

## คำอธิบาย

Text.Length ใช้นับจำนวนตัวอักษรทั้งหมดในสตริงข้อความ รวมถึงช่องว่างและอักขระพิเศษ ผลลัพธ์คืนค่าเป็นตัวเลข มีประโยชน์ในการตรวจสอบคุณภาพข้อมูล การกรองข้อมูลตามความยาว หรือการคำนวณ Logic ต่างๆ

## Syntax

```excel
Text.Length(text as nullable text) as nullable number
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | text |  | ข้อความที่ต้องการนับจำนวนตัวอักษร อาจเป็น null ได้ ถ้าเป็น null จะคืนค่า null |

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

### ตรวจสอบความยาวรหัส

เช็คว่ารหัสสินค้า หรือรหัสบัตรประชาชนมีจำนวนตัวอักษรตรงตามที่กำหนดหรือไม่

### ทำความสะอาดข้อมูล

ใช้ร่วมกับ Text.Trim เพื่อหาความยาวที่แท้จริงของเนื้อหา (ไม่รวมช่องว่างหน้าหลัง)

### วิเคราะห์ข้อความ

นับจำนวนตัวอักษรของข้อความในรีวิว เพื่อดูว่ารีวิวสั้นหรือยาว

## ตัวอย่าง

### 1. ตัวอย่างพื้นฐาน: นับตัวอักษรธรรมชาติ

```excel
= Text.Length("apple")
```

**ผลลัพธ์:** `5`

คำว่า "apple" มี 5 ตัวอักษร

### 2. นับรวมช่องว่าง

```excel
= Text.Length("hello world")
```

**ผลลัพธ์:** `11`

"hello world" มี 11 ตัวอักษร (h-e-l-l-o-space-w-o-r-l-d)

### 3. ใช้กับคอลัมน์ในตาราง

```excel
let
    Source = Table.FromRows({"apple", "banana", "kiwi"}),
    AddLength = Table.AddColumn(Source, "Length", each Text.Length([Value]))
in
    AddLength
```

**ผลลัพธ์:** `3 แถว พร้อมคอลัมน์ Length แสดง 5, 6, 4`

สร้างคอลัมน์ใหม่ที่แสดงความยาวข้อความสำหรับแต่ละแถว

### 4. กรองข้อมูลตามความยาว

```excel
let
    Customers = Table.FromRows({"John", "AB", "Christopher"}),
    LongNames = Table.SelectRows(Customers, each Text.Length([Name]) > 5)
in
    LongNames
```

**ผลลัพธ์:** `2 แถว: "John" (4, ไม่รวม), "Christopher" (11, รวม)`

กรองเหลือแค่ชื่อที่มีความยาวมากกว่า 5 ตัวอักษร

### 5. ตรวจสอบการจัดรูปแบบ (เช่น รหัสผ่าน)

```excel
let
    Password = "MyPass123",
    IsValid = Text.Length(Password) >= 8
in
    IsValid
```

**ผลลัพธ์:** `true`

ตรวจสอบว่ารหัสผ่านมีความยาวตั้งแต่ 8 ตัวอักษรขึ้นไป

### 6. ใช้กับ Text.Trim เพื่อเอาช่องว่างออก

```excel
= Text.Length(Text.Trim("  hello  "))
```

**ผลลัพธ์:** `5`

ถ้าไม่ trim ก็จะนับ 13 (รวมช่องว่าง 4 ตัว) แต่ trim ก่อนจะเหลือแค่ 5

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

- ใช้ Text.Length กับ Text.Trim เพื่อเอาช่องว่างหน้า-หลังออกก่อนนับ เพื่อให้ได้ความยาวที่แท้จริง

- ตรวจสอบ null ก่อนเสมอ ถ้าไม่แน่ใจให้ใช้ [Column]  null ก่อน

- ใช้กับ Table.SelectRows เพื่อกรองข้อมูลตามความยาว เช่น กรองรหัสสินค้าที่มีความยาวไม่ถูกต้อง

- ใช้ List.Transform กับ Text.Length เพื่อนับความยาวของรายการในลิสต์

- ส่วนตัวผม มักใช้ร่วมกับ Text.Start หรือ Text.End เพื่อตัดข้อความตามความยาวที่คำนวณได้

- ใช้ ?? operator เพื่อให้ค่า default ถ้าผลลัพธ์เป็น null เช่น Text.Length([Name]) ?? 0

- สามารถใช้เพื่อตรวจสอบคุณภาพข้อมูล เช่นตรวจสอบว่า ID ทั้งหมดมีความยาวเท่ากันไหม

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

**Q: Text.Length กับ Excel LEN() ต่างกันอย่างไร?**

ไม่ต่างครับ ทั้งสองทำหน้าที่เดียวกัน - นับตัวอักษร แต่ Text.Length ใช้ใน Power Query (M language) ส่วน LEN() ใช้ใน Excel Worksheet Function

**Q: ถ้าข้อความเป็น null จะเกิดอะไร?**

จะคืนค่า null ตัวเอง ถ้าต้องการให้คืนค่า 0 แทน ให้ใช้ Text.Length(...) ?? 0

**Q: นับอักขระพิเศษและ Unicode ด้วยไหม?**

นับครับ Text.Length นับทุกอักขระ ไม่ว่าจะเป็น ASCII, Unicode, emoji, สัญลักษณ์พิเศษ ก็นับหมด

**Q: การนับตัวอักษรไทยแตกต่างจาก English ไหม?**

ไม่ Text.Length นับตัวอักษรไทยเหมือนตัวอักษรอื่นๆ นับตัวอักษร 1 ตัวต่อ 1 ตัวอักษร

**Q: ใช้กับ List.Transform ได้ไหม?**

ได้ครับ ใช้ List.Transform({"apple", "banana"}, each Text.Length(_)) ได้ผลลัพธ์เป็น {5, 6}

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

- [Binary.Length – ได้ความยาว Binary](https://www.thepexcel.com/functions/power-query/binary-functions/binary-length/)
- [Text.End – ดึงอักขระจากท้ายข้อความ](https://www.thepexcel.com/functions/power-query/text-functions/text-end/)
- [Text.Start – ดึงอักขระจากตัวแรกของข้อความ](https://www.thepexcel.com/functions/power-query/text-functions/text-start/)
- [Text.Trim – ตัดอักขระนำหน้าและลงท้าย](https://www.thepexcel.com/functions/power-query/text-functions/text-trim/)

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

- [Microsoft Learn: Text.Length](https://learn.microsoft.com/en-us/powerquery-m/text-length) _(official)_
- [Microsoft Power Query M Reference](https://learn.microsoft.com/en-us/powerquery-m/) _(official)_
- [Text Functions in Power Query](https://learn.microsoft.com/en-us/powerquery-m/text-functions) _(official)_

---

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