Bảng tham số hàm GROUPBY

Tham số Bắt buộc/ Tùy chọn Giải thích chi tiết
row_fields Bắt buộc Mảng (array) chứa các trường (fields) dùng để nhóm dòng (giống như “Group by” theo cột nào).
values Bắt buộc Mảng giá trị mà bạn muốn thực hiện phép tính (như cộng tổng, đếm, trung bình…).
function Bắt buộc Hàm áp dụng: “SUM”, “COUNT”, “AVERAGE”, “MAX”, “MIN”, hoặc LAMBDA.
field_headers Tùy chọn Tiêu đề cho các cột kết quả.
total_depth Tùy chọn Mức độ nhóm nhiều cấp (ví dụ theo “Vùng” rồi “Quốc gia”).
sort_order Tùy chọn Sắp xếp tăng (1) hoặc giảm (-1). Mặc định là 1.
filter_array Tùy chọn Điều kiện lọc dữ liệu trước khi nhóm.
field_relationship Tùy chọn Mô tả quan hệ giữa các field khi nhóm phức tạp.
=GROUPBY(DATA_GROUPBY[[#All],[ProductName]], DATA_GROUPBY[[#All],[Amount]], SUM, 3)

Dưới đây là tham chiếu khi bạn chọn
DATA_GROUPBY[[#All],[ProductName]]

Reference with #All

Còn đây là tham chiếu khi bạn chọn
DATA_GROUPBY[ProductName]

Reference without #All

=GROUPBY(DATA_GROUPBY[ProductName],DATA_GROUPBY[Amount],SUM,3)
=VSTACK({“Product Name”,”Amount”},GROUPBY(DATA_GROUPBY[ProductName],DATA_GROUPBY[Amount],SUM,0))

=VSTACK({“Product Name”,”Amount”},GROUPBY(DATA_GROUPBY[ProductName],DATA_GROUPBY[Amount],SUM,,,,DATA_GROUPBY[ChannelName]=”Online”))

=GROUPBY(DATA_GROUPBY[[#All],[ProductName]:[ChannelName]],DATA_GROUPBY[[#All],[Amount]],SUM,3)
=GROUPBY(DATA_GROUPBY[[#All],[ProductName]:[ChannelName]],DATA_GROUPBY[[#All],[Amount]],SUM,3,,{-1,2})
=GROUPBY(DATA_GROUPBY[[ProductName]:[ChannelName]],DATA_GROUPBY[Amount],SUM,0,0,-3,,0)
=LET( group_by_array, GROUPBY( DATA_GROUPBY[[ProductName]:[ChannelName]], DATA_GROUPBY[Amount], SUM, 0, 0 ), VSTACK( {“Product Name”, “Channel Name”, “Amount”}, SORT(group_by_array, {1, 3}, {1, -1}), HSTACK( “Total”, “”, SUM(CHOOSECOLS(group_by_array, 3)) ) ) )

=GROUPBY(DATA_GROUPBY4[[#All],[ProductName]:[ChannelName]],DATA_GROUPBY4[[#All],[Amount]],SUM,3,1,-3,,1)
=GROUPBY(DATA_GROUPBY4[[#All],[ProductName]:[ChannelName]],DATA_GROUPBY4[[#All],[Amount]],SUM,3,1,-3)
field_relationship là Table
field_relationship là Table
field_relationship là Hierarchy (mặc định)
field_relationship là Hierarchy

=LET( result_array, SORT( GROUPBY( DATA_GROUPBY[[#All],[ProductName]:[ChannelName]], DATA_GROUPBY[[#All],[Amount]], SUM, 3 ), 2, 1 ), report_array, DROP(result_array, 1), grand_total_array, TAKE(result_array, 1), VSTACK(report_array, grand_total_array) )
=LET( result_array, SORT( GROUPBY( DATA_GROUPBY[[#All],[ProductName]:[ChannelName]], DATA_GROUPBY[[#All],[Amount]], SUM, 3 ), {2, 3}, {1, -1} ), report_array, DROP(result_array, 1), grand_total_array, TAKE(result_array, 1), VSTACK(report_array, grand_total_array) )
=GROUPBY( HSTACK( DATA_GROUPBY[[#All],[ChannelName]], DATA_GROUPBY[[#All],[ProductName]] ), DATA_GROUPBY[[#All],[Amount]], SUM, 3, 2 )

=VSTACK( {“Phòng ban”, “Email”}, HSTACK( SORT(UNIQUE(Z4:Z23)), BYROW( SORT(UNIQUE(Z4:Z23)), LAMBDA(row, TEXTJOIN( “; “, TRUE, FILTER(AA4:AA23, Z4:Z23 = row) ) ) ) ) )
=GROUPBY(Z3:Z23,AA3:AA23,ARRAYTOTEXT,3,0)
=GROUPBY(Z3:Z23,AA3:AA23,LAMBDA(x, SUBSTITUTE(ARRAYTOTEXT(x),”,”,”;”)),3,0)

=GROUPBY(Z46:Z346,AA46:AA346,LAMBDA(arr, ARRAYTOTEXT(SORT(UNIQUE(arr)))),,0)
=VSTACK( {“Division”, “Sales Manager”}, HSTACK( SORT(UNIQUE(Z47:Z346)), BYROW( SORT(UNIQUE(Z47:Z346)), LAMBDA(row, TEXTJOIN( “, “, TRUE, SORT( UNIQUE( FILTER( AA47:AA346, Z47:Z346 = row ) ) ) ) ) ) ) )

=GROUPBY(AA349:AA661,AC349:AC661,SUM,3,,,ISNUMBER(Y349:Y661))

=VSTACK( {“Sales Manager”, “% Sale”}, GROUPBY( AA350:AA661, AC350:AC661, PERCENTOF, 0, , -2, ISNUMBER(Y350:Y661) ) )
=VSTACK( {“Sales Manager”, “Total Sales”, “% Sales”}, LET( pct_sales, GROUPBY( AA350:AA661, AC350:AC661, PERCENTOF, 0, , -2, ISNUMBER(Y350:Y661) ), total_sales, GROUPBY( AA350:AA661, AC350:AC661, SUM, 0, , -2, ISNUMBER(Y350:Y661) ), HSTACK( total_sales, BYROW( CHOOSECOLS(total_sales, 1), LAMBDA(row, XLOOKUP( row, CHOOSECOLS(pct_sales, 1), CHOOSECOLS(pct_sales, 2) ) ) ) ) ) )

=LET( result_array, VSTACK( { “Month / Year”, “Sales Name”, “Sales Amount” }, DROP( GROUPBY( HSTACK( Y349:Y661, TEXT(Y349:Y661, “mmm/yyyy”), AA349:AA661 ), AC349:AC661, SUM, 0, 0, 1, ISNUMBER(Y349:Y661) ), , 1 ) ), VSTACK( result_array, HSTACK( “Total”, “”, SUM(CHOOSECOLS(result_array, 3)) ) ) )

=GROUPBY( DATA_GROUPBY5[[#All],[ProductName]], DATA_GROUPBY5[[#All],[Amount]], HSTACK(SUM, MIN, MAX, COUNTA, AVERAGE) )
=VSTACK( {“Sales Name”, “Total Orders”, “% Orders”}, DROP( GROUPBY( B2:B38, SEQUENCE(ROWS(C2:C38), , , 0), HSTACK(COUNTA, PERCENTOF) ), 1 ) )
=LET( orders_arr, VSTACK( {“Sales Name”, “Total Orders”, “% Orders”}, DROP( GROUPBY( B2:B38, SEQUENCE(ROWS(C2:C38), , , 0), HSTACK(COUNTA, PERCENTOF) ), 1 ) ), sales_arr, VSTACK( {“Sales Name”, “Total Sales”, “% Sales”}, DROP( GROUPBY( B2:B38, D2:D38, HSTACK(SUM, PERCENTOF) ), 1 ) ), sales_col, XLOOKUP( CHOOSECOLS(orders_arr, 1), CHOOSECOLS(sales_arr, 1), CHOOSECOLS(sales_arr, 2) ), pct_sales_col, XLOOKUP( CHOOSECOLS(orders_arr, 1), CHOOSECOLS(sales_arr, 1), CHOOSECOLS(sales_arr, 3) ), HSTACK(orders_arr, sales_col, pct_sales_col) )