Thep Excel

Table.ColumnCount – นับจำนวนคอลัมน์

นับจำนวนคอลัมน์ในตาราง

นับจำนวนคอลัมน์ในตาราง

=Table.ColumnCount(table as table) as number

By ThepExcel AI Agent
3 December 2025

Syntax & Arguments

=Table.ColumnCount(table as table) as number

Argument Type Required Default Description
table Table Yes ตารางข้อมูล

Examples

ตัวอย่างที่ 1: นับจำนวนคอลัมน์

ตารางมีคอลัมน์ CustomerID, Name, Sales รวมเป็น 3 คอลัมน์
Power Query Formula:

let
    Source = Table.FromRecords({
        [CustomerID = 1, Name = "Bob", Sales = 100],
        [CustomerID = 2, Name = "Jim", Sales = 200],
        [CustomerID = 3, Name = "Paul", Sales = 300]
    }),
    Result = Table.ColumnCount(Source)
in
    Result

Result:

3

ตัวอย่างที่ 2: ตรวจสอบโครงสร้างตาราง

นับคอลัมน์เพื่อเช็คว่าโครงสร้างตารางตรงตามที่คาดหวังหรือไม่
Power Query Formula:

let
    Source = Excel.CurrentWorkbook(){[Name="SalesData"]}[Content],
    ColumnCount = Table.ColumnCount(Source),
    Message = if ColumnCount = 5 then "โครงสร้างถูกต้อง" else "โครงสร้างไม่ตรง!"
in
    Message

Result:

"โครงสร้างถูกต้อง" หรือ "โครงสร้างไม่ตรง!"

ตัวอย่างที่ 3: คำนวณขนาดข้อมูล

ใช้ RowCount กับ ColumnCount ร่วมกันเพื่อคำนวณจำนวน Cell ทั้งหมด
Power Query Formula:

let
    Source = Table.FromRecords({
        [A = 1, B = 2],
        [A = 3, B = 4]
    }),
    RowCount = Table.RowCount(Source),
    ColCount = Table.ColumnCount(Source),
    TotalCells = RowCount * ColCount
in
    TotalCells

Result:

4

Resources & Related

Additional Notes

ฟังก์ชัน Table.ColumnCount ใช้นับจำนวนคอลัมน์ทั้งหมดในตาราง

Leave a Reply

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