search
HomeSoftware TutorialOffice SoftwareHow to Use the PIVOTBY Function in Excel

  • The PIVOTBY Syntax
  • PIVOTBY: Using the Required Arguments Only
  • PIVOTBY: Using the Optional Arguments

Excel's PIVOTBY function allows you to group your figures without needing to recreate your data in a PivotTable. What's more, data summaries created via PIVOTBY automatically update to reflect changes in your original data, and you can customize what they show by tweaking the formula.

The PIVOTBY Syntax

The PIVOTBY function lets you input a total of 11 arguments. Although this sounds daunting, the benefit of having so many arguments is that you can tailor the result to align with what you want the data to show.

However, only the first four fields are required.

Required Fields

The required PIVOTBY fields are where you tell Excel which variables you want to be displayed in rows, which variables you want to be displayed in columns, where to find the values, and how you want to aggregate your data:

=PIVOTBY(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>)

where

  • a are the cells containing the category or categories you want to appear as row headers down the left-hand side of your result,
  • b are the cells containing the category or categories you want to appear as column headers across the top of your result,
  • c are the values that will appear in the center of your result, according to the rows and columns you selected for arguments a and b, and
  • d is the Excel function (or function you've created yourself through LAMBDA) that defines how the data will be aggregated.
Optional Fields

The optional PIVOTBY fields allow you to include headers and totals, sort your data, and—in very specific circumstances—specify some additional parameters:

=PIVOTBY(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>,[<em>e</em>,<em>f</em>,<em>g</em>,<em>h</em>,<em>i</em>,<em>j</em>,<em>k</em>])

Argument

What It Is

Notes

e

A number that specifies whether arguments a, b, and c include headers and whether you want headers to be displayed in the result

0 = No headers (default)

1 = Headers, but don't show

2 = No headers, but generate them

3 = Headers, and show

f

A number that determines whether argument a should contain grand totals and subtotals

0 = No totals

1 = Grand totals at the bottom (default)

2 = Grand totals and subtotals at the bottom

-1 = Grand totals at the top

-2 = Grand totals and subtotals at the top

g

A number indicating how the columns should be sorted

The number refers to the columns in argument a, followed by the column in argument c. For example, if you had two columns in argument a, "2" would sort the result by the second column of this argument, and "3" would sort the result by argument c. A positive number represents alphabetical or ascending order, and a negative number represents the reverse.

h

A number that determines whether argument b should contain grand totals and subtotals

0 = No totals

1 = Grand totals on the right (default)

2 = Grand totals and subtotals on the right

-1 = Grand totals on the left

-2 = Grand totals and subtotals on the left

i

A number that indicates how the rows should be sorted

The number refers to the columns in argument b, followed by the column in argument c, and works in the same way as argument g.

j

A logical expression or formula that lets you filter out rows containing certain values or text

N/A

k

A number that gives you more control over how the result's calculations are performed when you use the PERCENTOF function in argument d

0 = Column totals (default)

1 = Row totals

2 = Grand total

3 = Parent column total

4 = Parent row total

PIVOTBY: Using the Required Arguments Only

First, let me show you how to use the PIVOTBY function in its simplest form with just the four required fields.

Let's say you've been handed this table of data named Sports_Viewers. It shows the live viewing figures (column D) for six sports (column B) across four regions (column C) over four years (column A), and you've been asked to generate a summary of total viewers by sport and year.

How to Use the PIVOTBY Function in Excel

How to Use the PIVOTBY Function in Excel

Related
How to Name a Table in Microsoft Excel

"Table1" doesn't explain much...

You could use the GROUPBY function to do this, though you would need to use optional arguments to produce a result that makes analysis easier. What's more, since GROUPBY only sorts data into rows, you could end up with a long list of information that is difficult to interpret.

How to Use the PIVOTBY Function in Excel

Instead, using the PIVOTBY function lets you take one or more of the variables and place them into columns, giving you a clearer picture of how your numbers stack up.

PIVOTBY: Using the Optional Arguments

Whenever you create an Excel formula, each argument is separated by a comma. This means that if you want to skip over any of the optional arguments, you simply need to type a first comma to open the argument, followed by a second comma to close it. The fact that there's nothing between these two commas tells Excel that you've deliberately omitted this argument, so you want the program to adopt the default setting.

How to Use the PIVOTBY Function in Excel

Related
The Beginner’s Guide to Excel’s Formulas and Functions

Everything you need to know about Excel's engine room.

1

Example 1: Grand Totals and Subtotals

One way to make the PIVOTBY result in the previous example clearer would be to add subtotal rows for each sport.

To do this, you need to type:

=PIVOTBY(Sports_Viewers[[Sport]:[Region]],Sports_Viewers[Year],Sports_Viewers[Viewers],SUM,,2)

Notice how, after argument d (SUM), two commas indicate that you want to jump over argument e (headers), but include argument f (in this case, 2 means that you want to include a subtotal at the bottom of each sport, as well as grand totals at the bottom of the overall result).

How to Use the PIVOTBY Function in Excel

Example 2: Sort Order

Now, let's look at another way to manipulate your result: sorting by one of the output columns.

Typing:

=PIVOTBY(Sports_Viewers[[Sport]:[Region]],Sports_Viewers[Year],Sports_Viewers[Viewers],SUM,,2,3)

means that, after skipping over argument e, as well as including grand totals and subtotals (number 2 in argument f), you also want to order your data by overall viewing figures in ascending order (number 3 in argument g).

How to Use the PIVOTBY Function in Excel

Notice how sorting by total viewing figures places not only the sports in order according to their overall totals, but also the regional subcategories according to their subtotals.

Example 3: Percentages (PERCENTOF)

Here's how to view your result using percentages.

Typing:

=PIVOTBY(Sports_Viewers[Sport],Sports_Viewers[Year],Sports_Viewers[Viewers],PERCENTOF,,,2,,,,2)

tells Excel that you want the sports as the row headers (argument a), the years as the column headers (argument b), and you want to aggregate your data (argument c) in the form of percentages (argument d). The first 2 (argument g) represents the order, which, in this case, is by the values. Finally, the second 2 (argument k) tells Excel that the percentages should be relative to the overall data. The unpopulated commas tell Excel you want it to adopt the default for arguments e, f, h, i, and j.

How to Use the PIVOTBY Function in Excel

How to Use the PIVOTBY Function in Excel

Related
Use the PERCENTOF Function to Simplify Percentage Calculations in Excel

Handle percentages like a pro!

Now, select the cells containing the decimalized results, and click the "Percent Style" icon in the Number group of the Home tab on the ribbon. While you're there, click the "Increase Decimal" and "Decrease Decimal" buttons to define the number of decimal places.

Select extra rows beneath the result in case more data is added to the original table in the future.

How to Use the PIVOTBY Function in Excel

Finally, take a moment to digest what this result tells you.

How to Use the PIVOTBY Function in Excel

For example, the number of people watching softball in 2022 constitutes 11.5% of the overall viewing figures for all sports across all years. Also, because the data is organized by the total column in ascending order, you can see that nearly a quarter (23.7%) of the overall viewing figures came from people watching basketball.


As well as using SUM, AVERAGE, and PERCENTOF for the function argument in PIVOTBY, you can also use other aggregation functions, like COUNT, MIN, or MAX.

The above is the detailed content of How to Use the PIVOTBY Function in Excel. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Microsoft 365 Will Turn Off ActiveX, Because Hackers Keep Using ItMicrosoft 365 Will Turn Off ActiveX, Because Hackers Keep Using ItApr 12, 2025 am 06:01 AM

Microsoft 365 is finally phasing out ActiveX, a long-standing security vulnerability in its Office suite. This follows a similar move in Office 2024. Beginning this month, Windows versions of Word, Excel, PowerPoint, and Visio in Microsoft 365 will

How to Use Excel's AGGREGATE Function to Refine CalculationsHow to Use Excel's AGGREGATE Function to Refine CalculationsApr 12, 2025 am 12:54 AM

Quick Links The AGGREGATE Syntax

How to Use the PIVOTBY Function in ExcelHow to Use the PIVOTBY Function in ExcelApr 11, 2025 am 12:56 AM

Quick Links The PIVOTBY Syntax

How to Format a Spilled Array in ExcelHow to Format a Spilled Array in ExcelApr 10, 2025 pm 12:01 PM

Use formula conditional formatting to handle overflow arrays in Excel Direct formatting of overflow arrays in Excel can cause problems, especially when the data shape or size changes. Formula-based conditional formatting rules allow automatic formatting to be adjusted when data parameters change. Adding a dollar sign ($) before a column reference applies a rule to all rows in the data. In Excel, you can apply direct formatting to the values ​​or background of a cell to make the spreadsheet easier to read. However, when an Excel formula returns a set of values ​​(called overflow arrays), applying direct formatting will cause problems if the size or shape of the data changes. Suppose you have this spreadsheet with overflow results from the PIVOTBY formula,

You Need to Know What the Hash Sign Does in Excel FormulasYou Need to Know What the Hash Sign Does in Excel FormulasApr 08, 2025 am 12:55 AM

Excel Overflow Range Operator (#) enables formulas to be automatically adjusted to accommodate changes in overflow range size. This feature is only available for Microsoft 365 Excel for Windows or Mac. Common functions such as UNIQUE, COUNTIF, and SORTBY can be used in conjunction with overflow range operators to generate dynamic sortable lists. The pound sign (#) in the Excel formula is also called the overflow range operator, which instructs the program to consider all results in the overflow range. Therefore, even if the overflow range increases or decreases, the formula containing # will automatically reflect this change. How to list and sort unique values ​​in Microsoft Excel

How to Create a Timeline Filter in ExcelHow to Create a Timeline Filter in ExcelApr 03, 2025 am 03:51 AM

In Excel, using the timeline filter can display data by time period more efficiently, which is more convenient than using the filter button. The Timeline is a dynamic filtering option that allows you to quickly display data for a single date, month, quarter, or year. Step 1: Convert data to pivot table First, convert the original Excel data into a pivot table. Select any cell in the data table (formatted or not) and click PivotTable on the Insert tab of the ribbon. Related: How to Create Pivot Tables in Microsoft Excel Don't be intimidated by the pivot table! We will teach you basic skills that you can master in minutes. Related Articles In the dialog box, make sure the entire data range is selected (

How to Use the GROUPBY Function in ExcelHow to Use the GROUPBY Function in ExcelApr 02, 2025 am 03:51 AM

Excel's GROUPBY function: Powerful data grouping and aggregation tools Excel's GROUPBY function allows you to group and aggregate data based on specific fields in a data table. It also provides parameters that allow you to sort and filter the data so that you can customize the output to your specific needs. GROUPBY function syntax The GROUPBY function contains eight parameters: =GROUPBY(a,b,c,d,e,f,g,h) Parameters a to c are required: a (row field): A range (one column or multiple columns) containing the value or category to which the data is grouped. b (value): The range of values ​​containing aggregated data (one column or multiple columns).

Don't Hide and Unhide Columns in Excel—Use Groups InsteadDon't Hide and Unhide Columns in Excel—Use Groups InsteadApr 01, 2025 am 12:38 AM

Excel efficient grouping: say goodbye to hidden columns and embrace flexible data management! While hidden columns can temporarily remove unnecessary data, grouping columns are often a better choice when dealing with large data sets or pursuing flexibility. This article will explain in detail the advantages and operation methods of Excel column grouping to help you improve data management efficiency. Why is grouping better than hiding? Hiding columns (right-click on the column title and select "Hide") can easily lead to data forgetting, even the column title prompt is not reliable because the title itself can be deleted. In contrast, grouped columns are faster and more convenient to expand and fold, which not only improves work efficiency, but also enhances user experience, especially when multi-person collaboration. Additionally, grouping columns allow creation of subgroups, which cannot be achieved by hidden columns. This is the number

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.