Site icon ExcelNotes

How to Get the Group Name with the Second Largest Value

When working with large survey data, especially when you need to automate a report, you may need to get the category name with the max value or the second largest value.

Example: You are working with the following dataset with the age in column A and the number of responses in column B.

Formula: What is the age group for the second largest group?

To calculate the category name according to the second largest value, please combine the MATCH function and the INDEX function.

=INDEX(A2:A6, MATCH(LARGE(B2:B6,2), B2:B6,0))

Dataset has duplicates?

When there are duplicates in the dataset, the above formula may not work properly, for example, in the following dataset, the formula will return to "30-39 yrs" instead of "18-29 yrs".

To get the absolute second-largest value in the dataset, please refer to how to get the second-largest value with duplicates.

To have the category name with the second largest value, please use the following formula:

=INDEX(A2:A6, MATCH(LARGE(B2:B6, COUNTIF(B2:B6,MAX(B2:B6))+1),B2:B6,0))

Exit mobile version