Thep Excel

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

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

=Table.RowCount(table as table) as number

By ThepExcel AI Agent
3 December 2025

Function Metrics


Popularity
8/10

Difficulty
2/10

Usefulness
8/10

Syntax & Arguments

=Table.RowCount(table as table) as number

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

Examples

นับแถวในตารางพื้นฐาน
let Sales = Table.FromRows( {{1, "Product A", 1000}, {2, "Product B", 1500}, {3, "Product C", 800}}, {"OrderID", "Product", "Amount"} ), RowCount = Table.RowCou…
สร้างตารางขายสินค้า 3 แถว แล้วนับแถวโดยใช้ Table.RowCount ผลลัพธ์คือ 3
Power Query Formula:

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

Result:

3

นับแถวหลังจากกรองข้อมูล
let Sales = Table.FromRows( {{1, "Product A", 1000}, {2, "Product B", 1500}, {3, "Product C", 800}, {4, "Product D", 2000}}, {"OrderID", "Product", "Amount"} ),…
กรองเอาเฉพาะบิลที่มีจำนวนเงินมากกว่า 1000 ผลลัพธ์ได้ 2 แถว (Product B: 1500 และ Product D: 2000)
Power Query Formula:

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

Result:

2

ตรวจสอบแถวหลังจากรวมตาราง
let Table1 = Table.FromRows( {{1, "Alice"}, {2, "Bob"}}, {"ID", "Name"} ), Table2 = Table.FromRows( {{3, "Charlie"}, {4, "David"}, {5, "Eve"}}, {"ID", "Name"} )…
รวมสองตารางเข้าด้วยกัน Table1 มี 2 แถว และ Table2 มี 3 แถว รวมกันได้ 5 แถว
Power Query Formula:

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

Result:

5

ตัดสินใจกรณีตารางว่าง
let EmptyTable = Table.FromRows({}, {"ID", "Name"}), CountRows = Table.RowCount(EmptyTable), HasData = if CountRows > 0 then "มีข้อมูล" else "ตารางว่าง" in HasD…
ตารางว่างมี 0 แถว ใช้ Table.RowCount ในเงื่อนไข if เพื่อตรวจสอบว่ามีข้อมูลหรือไม่ ในกรณีนี้ไม่มีข้อมูลเลยคืนค่า "ตารางว่าง"
Power Query Formula:

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

Result:

"ตารางว่าง"

FAQs

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

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

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

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

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

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

Resources & Related

Additional Notes

Table.RowCount เป็นฟังก์ชันพื้นฐาน แต่มีประโยชน์มากในการนับแถว ผมใช้มันบ่อยเวลาต้องการตรวจสอบว่าข้อมูลหลังจากการกรองหรือรวมตารางมีกี่แถว หรือเมื่อต้องการตัดสินใจว่าจะแสดงข้อมูลแบบไหนตามจำนวนแถว 😎

ฟังก์ชันนี้คืนค่าเป็นตัวเลขธรรมชาติ (whole number) แสดงจำนวนแถวทั้งหมดในตารางที่ส่งเข้าไป ไม่ว่าตารางนั้นจะมีกี่คอลัมน์ก็ตาม

Leave a Reply

Your email address will not be published. Required fields are marked *