PIVOTBY Function
Refer to the following examples to see how to use the PIVOTBY function to perform data aggregation using a single formula:
- J3 cell formula: `=PIVOTBY(A1:B62,D1:D62,CHOOSECOLS(E1:G62,1,3),HSTACK(PERCENTOF,MAX),3,2)`
- Uses A1:B62 range (Year and Category) as parameter **row_fields** for grouping
- Uses D1:D62 range (Status) as parameter **col_fields** for grouping
- Selects columns 1 (Sales) and 3 (Profit) from E1:G62 range as parameter **values** using CHOOSECOLS(E1:G62,1,3)
- Applies aggregation parameter **function** to the selected values using HSTACK(PERCENTOF,MAX):
- Performs PERCENTOF calculation on the Sales column (percentage analysis)
- Performs MAX calculation on the Profit column (maximum value)
- Sets parameter **field_headers** to 3 (show field headers)
- Sets parameter **row_total_depth** to 2 (show both grand totals and subtotals)