Thep Excel

Table.Group – จัดกลุ่มข้อมูล (Group By)

จัดกลุ่มข้อมูลและสรุปผล (Group By)

จัดกลุ่มข้อมูลและสรุปผล (Group By)

=Table.Group(table as table, key as any, aggregatedColumns as list, optional groupKind as nullable number, optional comparer as nullable function) as table

By ThepExcel AI Agent
3 December 2025

Syntax & Arguments

=Table.Group(table as table, key as any, aggregatedColumns as list, optional groupKind as nullable number, optional comparer as nullable function) as table

Argument Type Required Default Description
table Table Yes ตารางข้อมูลที่ต้องการจัดกลุ่ม
key Any Yes ชื่อคอลัมน์ที่ใช้จัดกลุ่ม (Text หรือ List of Text)
aggregatedColumns List Yes รายการคอลัมน์ใหม่ที่ต้องการสร้างจากการสรุปผล รูปแบบ {“NewColName”, each List.Sum([Col]), type number}
groupKind Number Optional ประเภทการจัดกลุ่ม (GroupKind.Global หรือ GroupKind.Local)

Examples

จัดกลุ่มและหาผลรวม

จัดกลุ่มตาม 'Category' และหาผลรวมของ 'Sales' เก็บไว้ในคอลัมน์ใหม่ชื่อ 'TotalSales'
Power Query Formula:

let
    Source = #table(
        type table [Category = text, Sales = number],
        {
            {"A", 100},
            {"A", 200},
            {"B", 300}
        }
    ),
    Grouped = Table.Group(
        Source,
        {"Category"},
        {{"TotalSales", each List.Sum([Sales]), type number}}     )
in
    Grouped

Result:

Table (Category, TotalSales)

จัดกลุ่มและนับจำนวนแถว

นับจำนวนรายการในแต่ละกลุ่มโดยใช้ Table.RowCount(_)
Power Query Formula:

let
    Source = #table(
        type table [Category = text, Sales = number],
        {
            {"A", 100},
            {"A", 200},
            {"B", 300}
        }
    ),
    Grouped = Table.Group(
        Source,
        {"Category"},
        {{"Count", each Table.RowCount(_), Int64.Type}}     )
in
    Grouped

Result:

Table (Category, Count)

Resources & Related

Additional Notes

ฟังก์ชัน Table.Group ใช้สำหรับจัดกลุ่มข้อมูลในตารางตามคอลัมน์ที่กำหนด และสามารถทำการสรุปผลข้อมูล (Aggregation) ในแต่ละกลุ่มได้ เช่น หาผลรวม, นับจำนวน หรือหาค่าเฉลี่ย

Leave a Reply

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