BYCOL function
The BYCOL function in Excel is a part of the dynamic array functions introduced in Excel 365 and Excel 2021. It allows you to perform a calculation across multiple columns and return an array of results, one for each column. This function is especially useful when you need to apply a formula to each column in a range and return the result as a row of values.
Syntax:
BYCOL(array, lambda)
Arguments:
- array: A range or array of data that you want to perform calculations on. This can be a range of cells or an array constant.
- lambda: A LAMBDA function or expression that defines the calculation to be applied to each column in the array. The LAMBDA function will be executed for each column individually.
Example:
Example 1: Sum of each column
- Data (in cells A1:C3):
1 2 3 4 5 6 7 8 9 - Formula:
=BYCOL(A1:C3, LAMBDA(col, SUM(col))) - Result:
12 15 18The formula calculates the sum of each column (A, B, C), and returns an array of results:
[12, 15, 18](sum of column 1, sum of column 2, sum of column 3).
Example 2: Average of each column
- Data (in cells A1:C3):
1 2 3 4 5 6 7 8 9 - Formula:
=BYCOL(A1:C3, LAMBDA(col, AVERAGE(col))) - Result:
4 5 6The formula calculates the average of each column (A, B, C), and returns the result
[4, 5, 6](average of column 1, average of column 2, average of column 3).
Example 3: Finding the maximum value of each column
- Data (in cells A1:C3):
1 2 3 4 5 6 7 8 9 - Formula:
=BYCOL(A1:C3, LAMBDA(col, MAX(col))) - Result:
7 8 9The formula calculates the maximum value in each column and returns the array
[7, 8, 9](maximum of column 1, maximum of column 2, maximum of column 3).
Key Points:
- Array Output: The BYCOL function returns an array of results, with one result for each column in the input array.
- Dynamic Arrays: The BYCOL function works with dynamic arrays, so the results will automatically spill over into adjacent cells if you do not wrap them in other functions.
- Custom Calculations: By using the LAMBDA function, you can define custom calculations that are applied to each column individually.
- Efficient Calculation: BYCOL makes it easier to perform operations on each column of a range without needing to use loops or array formulas manually.
Use Cases:
- Column-Based Calculations: Use BYCOL to apply calculations to each column of a dataset, such as summing, averaging, or finding the maximum.
=BYCOL(A1:C10, LAMBDA(col, SUM(col))) - Dynamic Reporting: When you need to dynamically calculate results for each column in a range, BYCOL can be used in combination with other functions to generate reports.
- Column-wise Custom Operations: If you have specific custom operations to apply to each column, you can use BYCOL with a LAMBDA function to define your own logic.