Contact

PIVOTBY Function in Microsoft Excel: Syntax, Examples & Troubleshooting

Lookup and Reference Intermediate Microsoft Excel

Build a two-axis Excel formula summary with PIVOTBY. Group region and quarter, control totals and sort order, filter rows and choose percentage denominators explicitly.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: PIVOTBY groups data along both rows and columns and aggregates the corresponding values. It returns a formula-based cross-tabulation. Microsoft explicitly distinguishes it from an actual PivotTable object, even when the visible summaries look similar.

Syntax and required inputs

=PIVOTBY(row_fields, col_fields, values, function, [field_headers], [row_total_depth], [row_sort_order], [col_total_depth], [col_sort_order], [filter_array], [relative_to])

The first four arguments are required. Row fields, column fields and values are aligned column-oriented arrays. Function is an aggregation lambda or a supported function such as SUM, AVERAGE or COUNT. Multiple field columns create additional grouping levels; multiple value columns or aggregation functions can create multiple aggregates.

Optional controls

  • field_headers: omitted automatic; 0 no input headers; 1 input headers present but not shown; 2 no input headers but generate labels; 3 input headers present and shown. Automatic checks text then numeric values to infer a header row.
  • row_total_depth / col_total_depth: omitted automatic; 0 none; 1 grand totals; 2 grand and subtotals; negative −1/−2 put corresponding totals first. Subtotals require multiple fields on that axis; deeper values require sufficient levels.
  • row_sort_order / col_sort_order: signed field/value positions for the respective axis; negative means reverse order. Vectors can sort only grouping fields. The reference swaps “rows/columns” in parts of these descriptions; the examples use index 1 on each axis, aligning the argument names with their corresponding field arrays.
  • filter_array: one Boolean per input row, with matching height.
  • relative_to: for aggregators taking subset and totalset, 0 or omitted means column totals; 1 row totals; 2 grand totals; 3 parent-column total; 4 parent-row total. It has no effect on a one-argument SUM aggregation.

Worked example: region by quarter

Use this fixed source table in A1:D7. Sales values are numeric.

Row A · Region B · Quarter C · Sales D · Status
1 Region Quarter Sales Status
2 East Q1 100 Paid
3 East Q2 150 Paid
4 West Q1 80 Paid
5 West Q2 120 Pending
6 East Q1 50 Pending
7 West Q2 30 Paid
  1. Reserve a clear output area starting F2.
  2. Enter =PIVOTBY(A2:A7,B2:B7,C2:C7,SUM,0,0,1,0,1).
  3. The expected grouped numeric matrix is:
Region Q1 Q2
East 150 150
West 80 150

Input headers are excluded, so header mode is 0. Both total-depth controls are 0, and each axis uses ascending key order. Quarter category labels still identify the grouped columns; do not confuse those categories with optional field-header labels.

Second example: filter before aggregation

=PIVOTBY(A2:A7,B2:B7,C2:C7,SUM,0,0,1,0,1,D2:D7="Paid")

Expected matrix: East/Q1 100, East/Q2 150, West/Q1 80, West/Q2 30. All four category combinations remain present in this fixture, so it does not rely on an assumed representation for empty combinations. The filtered matrix totals 360.

Advanced application: make the percentage denominator explicit

Use a two-argument lambda and choose grand totals:

=PIVOTBY(A2:A7,B2:B7,C2:C7,LAMBDA(subset,totalset,SUM(subset)/SUM(totalset)),0,0,1,0,1,,2)

The final 2 selects the grand-total denominator of 530. Expected shares are East/Q1 150/530, East/Q2 150/530, West/Q1 80/530, West/Q2 150/530. These are approximately 28.30188679%, 28.30188679%, 15.09433962%, 28.30188679% and sum to 100%.

With the default relative_to 0, denominators would instead be the column totals, 230 for Q1 and 300 for Q2. Percentage labels must state which comparison was selected.

Troubleshooting

Keep ranges the same height and output cells unobstructed. An incorrect header mode can remove or group a real data row. A spill result is not a PivotTable and should not be used as a GETPIVOTDATA target merely because it resembles one.

Check function availability in the actual build before diagnosing input errors. The source’s broad Applies To list includes older perpetual versions, while the separately reviewed rollout announcement concerns Current Channel availability; this guide does not certify the older builds. No native PivotTable or PIVOTBY execution is claimed.

Compatibility and verification

Microsoft’s reference checked on October 17, 2026 lists: Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel 2024 Excel 2024 for Mac Excel 2021 Excel 2021 for Mac. Microsoft’s alphabetical catalog, checked October 17, 2026, identifies PIVOTBY with a Microsoft 365 introduction marker. That marker does not establish an exact rollout date, update channel or perpetual-license release. The last functioning version is unverified; no retirement is asserted.

Microsoft’s GROUPBY/PIVOTBY announcement, retrieved October 17, 2026, records general availability in the Current Channel on September 25, 2024. This channel milestone does not establish support in every perpetual release or the first preview build. Test recognition in the intended Microsoft 365 build; do not use a broad Applies To list alone as proof of older-version support.

Example verification: Expected numerical results are independently calculated; text and shape expectations follow the documented contract. These examples have not been tested in Microsoft Excel. No screenshot or native execution is claimed.