# PIVOTBY

## Content

This function is a powerful tool that allows you to create a summary of your data using a formula. It supports grouping along two axes and aggregating the associated values. This function is like the GROUPBY function but with the added capability of grouping data by both rows and columns.

>type=note
> **Note**: PIVOTBY is a dynamic array formula, and you need to enable the dynamic array feature in the Workbook.

## Syntax

`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])`

## Arguments

The function has following arguments.

| **Arguments** | **Description** |
| --------- | ----------- |
| *row\_fields* | [Required] A column-oriented array or range that contains the values used to group rows and generate row headers. |
| *col\_fields* | [Required] A column-oriented array or range that contains the values used to group columns and generate column headers. |
| *values* | [Required] A column-oriented array or range of the data to aggregate. |
| *function* | [Required] A lambda function or eta reduced lambda (e.g., SUM, AVERAGE, COUNT) that defines how to aggregate the values. |
| *field\_headers* | [Optional] Specifies whether the row\_fields, col\_fields, and values have headers and whether field headers should be returned in the results. |
| *row\_total\_depth* | [Optional] Determines whether the row headers should contain totals. |
| *row\_sort\_order* | [Optional] Indicates how rows should be sorted. |
| *col\_total\_depth* | [Optional] Determines whether the column headers should contain totals. |
| *col\_sort\_order* | [Optional] Indicates how columns should be sorted. |
| *filter\_array* | [Optional] A column-oriented 1D array of Booleans that indicate whether the corresponding row of data should be considered. |
| *relative\_to* | [Optional] Controls which values are provided to the second argument of the aggregation function, typically used with the PERCENTOF function. |

## Remarks

* PIVOTBY function supports Excel import and export.
* PIVOTBY is a dynamic array function which automatically spills the results into as many cells as needed.

## Example

`PIVOTBY (B2:B34,A2:A34,D2:D34,SUM)`