---
title: Table.RowCount – นับจำนวนแถวในตาราง
url: https://www.thepexcel.com/functions/power-query/table-functions/table-rowcount/
type: function-explainer
program: Power Query
syntax: Table.RowCount(table as table) as number
date: 2025-12-03
updated: 2025-12-22
scores:
  popularity: 8
  difficulty: 2
  usefulness: 8
---

# Table.RowCount – นับจำนวนแถวในตาราง

> ฟังก์ชันสำหรับนับจำนวนแถวทั้งหมดในตาราง โดยคืนค่าเป็นตัวเลขครับ

## คำอธิบาย

ฟังก์ชันสำหรับนับจำนวนแถวทั้งหมดในตาราง โดยคืนค่าเป็นตัวเลขครับ

## Syntax

```excel
Table.RowCount(table as table) as number
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| table | Yes | table |  | ตารางที่ต้องการนับจำนวนแถว สามารถเป็นตารางจากแหล่งข้อมูลใดก็ได้ (Excel, CSV, Database, API ฯลฯ) หรือตารางที่เกิดจากการแปลง |

## ตัวอย่าง

### 1. นับแถวในตารางพื้นฐาน

```excel
let
    Sales = Table.FromRows(
        {{1, "Product A", 1000}, {2, "Product B", 1500}, {3, "Product C", 800}},
        {"OrderID", "Product", "Amount"}
    ),
    RowCount = Table.RowCount(Sales)
in
    RowCount
```

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

สร้างตารางขายสินค้า 3 แถว แล้วนับแถวโดยใช้ Table.RowCount ผลลัพธ์คือ 3

### 2. นับแถวหลังจากกรองข้อมูล

```excel
let
    Sales = Table.FromRows(
        {{1, "Product A", 1000}, {2, "Product B", 1500}, {3, "Product C", 800}, {4, "Product D", 2000}},
        {"OrderID", "Product", "Amount"}
    ),
    FilteredSales = Table.SelectRows(Sales, each [Amount] > 1000),
    CountAfterFilter = Table.RowCount(FilteredSales)
in
    CountAfterFilter
```

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

กรองเอาเฉพาะบิลที่มีจำนวนเงินมากกว่า 1000 ผลลัพธ์ได้ 2 แถว (Product B: 1500 และ Product D: 2000)

### 3. ตรวจสอบแถวหลังจากรวมตาราง

```excel
let
    Table1 = Table.FromRows(
        {{1, "Alice"}, {2, "Bob"}},
        {"ID", "Name"}
    ),
    Table2 = Table.FromRows(
        {{3, "Charlie"}, {4, "David"}, {5, "Eve"}},
        {"ID", "Name"}
    ),
    CombinedTable = Table.Combine({Table1, Table2}),
    TotalRows = Table.RowCount(CombinedTable)
in
    TotalRows
```

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

รวมสองตารางเข้าด้วยกัน Table1 มี 2 แถว และ Table2 มี 3 แถว รวมกันได้ 5 แถว

### 4. ตัดสินใจกรณีตารางว่าง

```excel
let
    EmptyTable = Table.FromRows({}, {"ID", "Name"}),
    CountRows = Table.RowCount(EmptyTable),
    HasData = if CountRows > 0 then "มีข้อมูล" else "ตารางว่าง"
in
    HasData
```

**ผลลัพธ์:** `"ตารางว่าง"`

ตารางว่างมี 0 แถว ใช้ Table.RowCount ในเงื่อนไข if เพื่อตรวจสอบว่ามีข้อมูลหรือไม่ ในกรณีนี้ไม่มีข้อมูลเลยคืนค่า "ตารางว่าง"

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

- ใช้ Table.RowCount เพื่อตรวจสอบจำนวนแถวในทุกขั้นตอนของการแปลง ช่วยให้มั่นใจว่าไม่มีการสูญเสียข้อมูล

- รวม Table.RowCount กับเงื่อนไข if-then-else เพื่อตัดสินใจว่าจะใช้กระบวนการใดตามจำนวนแถว (เช่น ถ้ามี 0 แถวให้ขึ้น error)

- ใช้ Table.RowCount บวก Table.ColumnCount เพื่อได้ข้อมูลมิติของตารางแบบสมบูรณ์

- เมื่อต้องการสร้างเลขลำดับหรือหมายเลขแถว ลองใช้ Table.AddIndexColumn และตรวจสอบด้วย Table.RowCount

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

**Q: Table.RowCount จะคิด Header Row เข้าไปหรือไม่?**

ไม่ครับ Table.RowCount นับเฉพาะ Data Rows เท่านั้น Header Row จะไม่รวม หากตารางมี Header คือ "ID, Name, Amount" และ Data 3 แถว ผลลัพธ์ก็คือ 3 ไม่ใช่ 4

**Q: ถ้าตารางมีคอลัมน์เยอะเลยจะเป็นปัญหาไหม?**

ไม่เป็นปัญหาเลย Table.RowCount ไม่สนใจจำนวนคอลัมน์ มันนับแถวเท่านั้น ตารางกว้างแค่ไหนก็ตาม ผลลัพธ์เหมือนกัน

**Q: การใช้ Table.RowCount บนตารางขนาดใหญ่ (millions of rows) จะช้าไหม?**

มันควรจะเร็วครับ Power Query จัดการ Table.RowCount ได้อย่างมีประสิทธิภาพ แม้แต่ตารางขนาดใหญ่ก็ตาม แต่ถ้าตารางนั้นเกิดจากการแปลงที่ซับซ้อนมากๆ อาจต้องคำนวณก่อน ซึ่งอาจใช้เวลา

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

- [Table.ColumnCount](https://www.thepexcel.com/functions/power-query/table-functions/table-columncount/)
- [List.Count – นับจำนวนรายการในลิสต์](https://www.thepexcel.com/functions/power-query/list-functions/list-count/)
- [Table.SelectRows – กรองแถวตามเงื่อนไขใน Power Query](https://www.thepexcel.com/functions/power-query/table-functions/table-selectrows/)
- [Table.Combine – รวมหลาย table เข้าด้วยกัน](https://www.thepexcel.com/functions/power-query/table-functions/table-combine/)

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

- [Microsoft Learn - Official Documentation](https://learn.microsoft.com/en-us/powerquery-m/table-rowcount) _(official)_
- [PowerQuery.how - Power Query Tutorial](https://powerquery.how/table-rowcount/) _(article)_

---

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