TABLE OF CONTENTS

GROUPBY Function in Excel

The GROUPBY function summarises data by grouping rows and aggregating values.

5 Minute Read
Table showing the GROUBY Function

GROUPBY Function Definition

The GROUPBY function summarises data by grouping rows and aggregating values. It works exactly like a pivot table, except it’s a formula. The GROUBY function was introduced in November 2023 as an alternative to using Pivot Tables.

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

Breakdown of the inputs (arguments):

  • Row_fields: The values you are grouping by. For example, names of employees.
  • Values: The values you are aggregating by. For example, sales amounts.
  • Function: The calculation for aggregating. For example, SUM of the sales amounts by employee.
  • [Field_Headers]: Optional input to add or remove the headers.
  • [Total_depth]: Optional input to add or remove totals and subtotals.
  • [Sort_Order]: Optional input to sort from largest to smallest or smallest to largest.
  • [Filter_Array]: Optional input to filter for specific rows. For example, only show the results for the employee “Bill.”

GROUPBY Example

In the table below, suppose you want to find the sum of sales by country.

For this we use the GROUPBY function and select all of the countries as the row_fields, all of the sales as the values, and the SUM as the function. That returns a table breakdown of the sales by country.

GROUPBY Headers (Field_Headers) and Totals (Total_Depth)

Using the same table as the example above, suppose we want to see the headers in the results table. For that we would type a 3 just after the SUM, which tells Excel to show the headers.

After the field_headers, if we wanted to show the totals, we would add a 1 to show the grand totals as the total_depth argument in the GROUPBY function.

GROUPBY Sorting (Sort_Order)

To sort the GROUPBY results table, you can use the sort_order optional argument. You can choose what column in the results table to sort by. For example, a 1 would sort by the country results column, while a 2 would sort by the sales results column.

In this case, we have a 2, so it sorts by the sales column from lowest to highest (ascending order). To switch to descending order add a negative sign in front of the number.

GROUPBY with Filter (Filter_Array)

To filter the GROUPBY results to only show a specific value match, use the optional filter_array argument. In the example below, we selected the country column and make it equal to Spain in quotations. That tells Excel we only want to GROUPBY those values that are in Spain. As such, the results table only shows Spain and ignores all other countries in the original source.

PIVOTBY Function Example

The GROUPBY function only allows for row fields. If you also want to add column fields, you can use the PIVOTBY function instead.

The arguments are exactly the same as the GROUPBY, except there’s a column_fields argument as well.

In the example below, we added the countries as the rows and the quarters as the columns. As you can see in the results table, we have all the countries as row values, and all the quarters as column values.

GROUPBY vs Pivot Tables Difference

With Pivot Tables, you need to click the refresh button every time the original data changes. However, with the GROUPBY function the results automatically update. That’s the main difference between the two.

This applies to changing values in the linked dataset, as well as to new rows or columns being added. The GROUPBY function will automatically account for them, while the PIVOT TABLES will require a refresh.

GROUPBY and PIVOTBY Video Lesson

For a video tutorial of the GROUPBY and the PIVOTBY Functions, click on the video below.

Additional Resources

If you found this article useful, consider checking out our Excel for Business & Finance Course. Most courses are too simplified and don’t cover what it’s actually like on the job. That’s why we’ve drawn from our experience at industry-leading companies like Tesla, Amazon, or Goldman Sachs to teach you exactly what you need.

Other Articles You Might Find Helpful

Introduction

Building a cash flow statement from scratch using a company income statement and balance sheet is one of the most fundamental finance exercises commonly used to test interns and full-time professionals at elite level finance firms.

Test hyperlink

Image caption goes here
Sample Image Insertion
Dolor enim eu tortor urna sed duis nulla. Aliquam vestibulum, nulla odio nisl vitae. In aliquet pellentesque aenean hac vestibulum turpis mi bibendum diam. Tempor integer aliquam in vitae malesuada fringilla.

Elit nisi in eleifend sed nisi. Pulvinar at orci, proin imperdiet commodo consectetur convallis risus. Sed condimentum enim dignissim adipiscing faucibus consequat, urna. Viverra purus et erat auctor aliquam. Risus, volutpat vulputate posuere purus sit congue convallis aliquet. Arcu id augue ut feugiat donec porttitor neque. Mauris, neque ultricies eu vestibulum, bibendum quam lorem id. Dolor lacus, eget nunc lectus in tellus, pharetra, porttitor.

  • Test Bullet List 1
  • Test Bullet List 2
  • Test Bullet List 3
"Ipsum sit mattis nulla quam nulla. Gravida id gravida ac enim mauris id. Non pellentesque congue eget consectetur turpis. Sapien, dictum molestie sem tempor. Diam elit, orci, tincidunt aenean tempus."

Tristique odio senectus nam posuere ornare leo metus, ultricies. Blandit duis ultricies vulputate morbi feugiat cras placerat elit. Aliquam tellus lorem sed ac. Montes, sed mattis pellentesque suscipit accumsan. Cursus viverra aenean magna risus elementum faucibus molestie pellentesque. Arcu ultricies sed mauris vestibulum.

Conclusion

Morbi sed imperdiet in ipsum, adipiscing elit dui lectus. Tellus id scelerisque est ultricies ultricies. Duis est sit sed leo nisl, blandit elit sagittis. Quisque tristique consequat quam sed. Nisl at scelerisque amet nulla purus habitasse.

Nunc sed faucibus bibendum feugiat sed interdum. Ipsum egestas condimentum mi massa. In tincidunt pharetra consectetur sed duis facilisis metus. Etiam egestas in nec sed et. Quis lobortis at sit dictum eget nibh tortor commodo cursus.

Odio felis sagittis, morbi feugiat tortor vitae feugiat fusce aliquet. Nam elementum urna nisi aliquet erat dolor enim. Ornare id morbi eget ipsum. Aliquam senectus neque ut id eget consectetur dictum. Donec posuere pharetra odio consequat scelerisque et, nunc tortor.
Nulla adipiscing erat a erat. Condimentum lorem posuere gravida enim posuere cursus diam.

Kenji Farre
Kenji Farre
Senior Instructor

Ready to Level Up Your Career?

Learn the practical skills used at Fortune 500 companies across the globe.