搜索
首页专题excelexcel groupby函数可分组行和汇总值

Unlock the Power of Excel's GROUPBY Function for Enhanced Data Analysis! This function simplifies data grouping, summarization, sorting, and filtering, all within a single formula. Say goodbye to complex outlines, subtotals, and pivot tables – GROUPBY streamlines your workflow.

Excel's data analysis capabilities just got a significant boost. While features like outlines and pivot tables have long been staples for organizing and interpreting data, the new GROUPBY function offers a more streamlined approach, all within the convenience of your formula bar.

  • Understanding the Excel GROUPBY Function: Syntax and Basic Applications
  • GROUPBY Function Availability and Compatibility
  • Constructing a Basic GROUPBY Formula
  • Mastering GROUPBY: Advanced Formula Examples
    • Selecting the Right Aggregation Function
    • Displaying Headers Effectively
    • Grouping Rows Using Multiple Columns
    • Grouping with Non-Adjacent Columns
    • Controlling the Display of Totals and Subtotals
    • Sorting Grouped Data
    • Filtering Results
    • Aggregating Multiple Columns (Adjacent and Non-Adjacent)
    • Multiple Aggregations on a Single Dataset
    • Handling Comma-Separated Text Strings
  • Auto-Formatting GROUPBY Results with Conditional Formatting
  • Troubleshooting GROUPBY Function Issues

The Excel GROUPBY Function

The GROUPBY function efficiently groups and aggregates data rows based on values in one or more columns. It also supports sorting and filtering of grouped data. As a dynamic array function, it returns multiple results, spilling into adjacent cells. The output resembles a pivot table without the formatting; the spill range dynamically recalculates with data changes. This is particularly beneficial for large datasets requiring summarized data through functions like SUM, AVERAGE, or COUNT.

Excel GROUPBY function to group rows and aggregate values

Note: GROUPBY is similar to PIVOTBY, but GROUPBY exclusively groups data in rows.

Function Syntax

GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array])

Seven arguments are available, but only the first three are mandatory:

  • row_fields (required): The range of values to group by.
  • values (required): The values to aggregate.
  • function (required): The aggregation function (e.g., SUM, AVERAGE, COUNT, MIN, MAX).
  • field_headers (optional): Controls header display (0: No headers, 1: Yes, but don't show, 2: No headers, but generate, 3: Yes, and show).
  • total_depth (optional): Controls total/subtotal display (0: No totals, 1: Grand total at bottom, 2: Grand and subtotals at bottom, -1: Grand total at top, -2: Grand and subtotals at top).
  • sort_order (optional): Sorts by column index (positive for ascending, negative for descending). Arrays allow multi-column sorting.
  • filter_array (optional): Filters rows using a Boolean array.

Usage Tips

  • Dynamic Updates: The formula dynamically adjusts to dataset changes within its range. Adding new rows requires including them in the argument ranges or using an Excel table for automatic expansion.
  • Header Detection: If field_headers is omitted, Excel infers headers based on the values argument (text followed by a number suggests headers).
  • Range Consistency: row_fields and values must have equal lengths to avoid #VALUE! errors.
  • Conditional Formatting: Enhance readability by using conditional formatting to highlight totals and subtotals.

Note: GROUPBY is under development; thorough testing is recommended.

GROUPBY Function Availability

Currently available in Excel for Microsoft 365 (Insider Beta Channel).

Basic GROUPBY Formula

Let's assume a dataset with project names (Column A), types (Column B), and revenues (Column C). To summarize revenues by project type:

=GROUPBY(B2:B32, C2:C32, SUM)

This yields a list of unique project types with their revenue sums. Defaults are used for optional arguments (no headers, ascending sort, grand total at bottom).

Excel GROUPBY function to group rows and aggregate values

Advanced GROUPBY Formula Examples

This section expands on the basic example, demonstrating the function's versatility.

Choosing the Aggregation Function

GROUPBY supports 16 aggregation functions, including standard functions (SUM, AVERAGE, COUNT, etc.) and specialized ones (PERCENTOF, ARRAYTOTEXT). These are eta-reduced lambdas, simplifying usage. Custom lambda functions are also supported. Multiple aggregations are possible using vectors (vertical for column stacking, horizontal for row stacking).

Displaying Headers

Use the field_headers argument (set to 3) to include headers in the output.

=GROUPBY(B2:B32, C2:C32, SUM, 3)

Excel GROUPBY function to group rows and aggregate values

Grouping by Multiple Columns

Include a multi-column range in row_fields to group by multiple columns. For example, grouping by project type and status:

=GROUPBY(B2:C32, D2:D32, COUNT)

Excel GROUPBY function to group rows and aggregate values

Grouping by Non-Adjacent Columns

Use CHOOSECOLS to select non-adjacent columns for grouping:

=GROUPBY(CHOOSECOLS(A2:D32, 2, 4), C2:C32, COUNT)

Excel GROUPBY function to group rows and aggregate values

Controlling Totals and Subtotals

Use total_depth to control total/subtotal display. Setting it to 2 shows both grand and subtotals.

=GROUPBY(B2:C32, D2:D32, SUM, 3, 2)

Excel GROUPBY function to group rows and aggregate values

Sorting Grouped Rows

Use sort_order for custom sorting (positive for ascending, negative for descending). Arrays enable multi-column sorting.

=GROUPBY(B2:B32, C2:C32, SUM, , , 2) (Sorts by values)

Excel GROUPBY function to group rows and aggregate values

=GROUPBY(B2:C32, D2:D32, SUM, , , {-1,2}) (Multi-column sort)

Excel GROUPBY function to group rows and aggregate values

Filtering Results

Use filter_array (Boolean array) to filter rows.

=GROUPBY(B2:B32, C2:C32, SUM, , , , B2:B32"Design")

Excel GROUPBY function to group rows and aggregate values

Aggregating Multiple Columns

Aggregate adjacent columns directly:

=GROUPBY(B2:B32, D2:E32, AVERAGE, 3)

Excel GROUPBY function to group rows and aggregate values

For non-adjacent columns, use CHOOSECOLS:

=GROUPBY(B2:B32, CHOOSECOLS(C2:E32, 1, 3), AVERAGE, 3)

Excel GROUPBY function to group rows and aggregate values

Multiple Aggregations on the Same Data

Use HSTACK or VSTACK for multiple aggregations:

=GROUPBY(B3:B32, C3:C32, HSTACK(SUM, AVERAGE, PERCENTOF))

Excel GROUPBY function to group rows and aggregate values

=GROUPBY(B3:B32, C3:C32, VSTACK(SUM, AVERAGE, MIN, MAX),, 0)

Excel GROUPBY function to group rows and aggregate values

Grouping Comma-Separated Text Values

Use ARRAYTOTEXT to group comma-separated text:

=GROUPBY(B3:B23, A3:A23, ARRAYTOTEXT, 0, 0)

Excel GROUPBY function to group rows and aggregate values

Conditional Formatting of GROUPBY Results

Enhance visual clarity using conditional formatting to highlight headers, totals, and subtotals.

Troubleshooting GROUPBY Function Issues

  • Function Unavailability: Ensure you have a Microsoft 365 subscription and the latest updates.
  • #VALUE! Error: Check for equal lengths in row_fields and values arguments, and ensure correct filter_array length. Also, verify that total_depth is appropriate for the number of columns in row_fields.
  • #SPILL! Error: Clear adjacent cells to allow spill range.

In conclusion, the GROUPBY function significantly enhances Excel's data analysis capabilities, providing a powerful and efficient tool for various data manipulation tasks. With practice, you'll unlock its full potential for insightful data analysis.

以上是excel groupby函数可分组行和汇总值的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Excel中的中位公式 - 实际示例Excel中的中位公式 - 实际示例Apr 11, 2025 pm 12:08 PM

本教程解释了如何使用中位功能计算Excel中数值数据中位数。 中位数是中心趋势的关键度量

Google电子表格Countif函数带有公式示例Google电子表格Countif函数带有公式示例Apr 11, 2025 pm 12:03 PM

Google主张Countif:综合指南 本指南探讨了Google表中的多功能Countif函数,展示了其超出简单单元格计数的应用程序。 我们将介绍从精确和部分比赛到Han的各种情况

Excel共享工作簿:如何为多个用户共享Excel文件Excel共享工作簿:如何为多个用户共享Excel文件Apr 11, 2025 am 11:58 AM

本教程提供了共享Excel工作簿,涵盖各种方法,访问控制和冲突解决方案的综合指南。 现代Excel版本(2010年,2013年,2016年及以后)简化了协作编辑,消除了M的需求

如何将Excel转换为JPG-保存.xls或.xlsx作为图像文件如何将Excel转换为JPG-保存.xls或.xlsx作为图像文件Apr 11, 2025 am 11:31 AM

本教程探讨了将.xls文件转换为.jpg映像的各种方法,包括内置的Windows工具和免费的在线转换器。 需要创建演示文稿,安全共享电子表格数据或设计文档吗?转换哟

excel名称和命名范围:如何定义和使用公式excel名称和命名范围:如何定义和使用公式Apr 11, 2025 am 11:13 AM

本教程阐明了Excel名称的功能,并演示了如何定义单元格,范围,常数或公式的名称。 它还涵盖编辑,过滤和删除定义的名称。 Excel名称虽然非常有用,但通常是泛滥的

标准偏差Excel:功能和公式示例标准偏差Excel:功能和公式示例Apr 11, 2025 am 11:01 AM

本教程阐明了平均值的标准偏差和标准误差之间的区别,指导您掌握标准偏差计算的最佳Excel函数。 在描述性统计中,平均值和标准偏差为interinsi

Excel中的平方根:SQRT功能和其他方式Excel中的平方根:SQRT功能和其他方式Apr 11, 2025 am 10:34 AM

该Excel教程演示了如何计算正方根和n根。 找到平方根是常见的数学操作,Excel提供了几种方法。 计算Excel中正方根的方法: 使用SQRT函数:

Google表基础知识:了解如何使用Google电子表格Google表基础知识:了解如何使用Google电子表格Apr 11, 2025 am 10:23 AM

解锁Google表的力量:初学者指南 本教程介绍了Google Sheets的基础,这是MS Excel的强大而多才多艺的替代品。 了解如何轻松管理电子表格,利用关键功能并协作

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具