array search for top 2 values of each product

gvillepa

New Member
Joined
Oct 18, 2017
Messages
36
Hey folks, Could use the assistance by those smarter than me!

Each sales person sells 2 categories. There are 2 products in each category. Trying to find a way to return the Top 2 largest values for each product:

Red Delicious Apple Highest Sales = John Smith
Red Delicious Apple 2nd Highest Sales = Bob Smith
Orange Valencia Highest Sales = Bob Smith
Orange Valenicia 2nd Highest Sales = John Doe (A tie doesnt matter so long as highest and 2nd highest reflect the tie).

Was thinking just an index with large function. Not worried about aesthetics (i can clean up on the formatting and the way it returns, just need function assistance) Help is appreciated, thanks!

NameProductTypeSales
John DoeAppleRed Delicious9
John DoeAppleGranny Smith8
John DoeOrangeValencia7
John DoeOrangeClementine3
Bob SmithAppleRed Delicious1
Bob SmithAppleGranny Smith16
Bob SmithOrangeValencia7
Bob SmithOrangeClementine3

<tbody>
</tbody>
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Book1
ABCDEFG
1NameProductTypeSalesappleorange
2gvillepaAppleRed Delicious9red deliciousvalencia
3John DoeAppleGranny Smith822
4John DoeOrangeValencia7gvillepaJohn Doe
5John DoeOrangeClementine3Bob SmithBob Smith
6Bob SmithAppleRed Delicious1
7Bob SmithAppleGranny Smith16
8Bob SmithOrangeValencia7
9Bob SmithOrangeClementine3
Sheet1


In F3 control+shift+enter, not just enter, and copy across:

=COUNTIFS($C$2:$C$9,F$2,$D$2:$D$9,">="&LARGE(IF($C$2:$C$9=F$2,$D$2:$D$9),MIN(2,COUNTIFS($C$2:$C$9,F$2))))

In F4 control+shift+enter, not just enter, and copy down:

=IF(ROWS(F$4:F4)<=F$3,INDEX($A$2:$A$9,SMALL(IF($D$2:$D$9=LARGE(IF($C$2:$C$9=F$2,$D$2:$D$9),ROWS(F$4:F4)),ROW($D$2:$D$9)-ROW($D$2)+1),
SUM(IF(LARGE(IF($C$2:$C$9=F$2,$D$2:$D$9),ROW(F$4:F4)-ROW(F$4)+1)=LARGE(IF($C$2:$C$9=F$2,$D$2:$D$9),ROWS(F$4:F4)),1)))),"")
 
Upvote 0
Data range A1:D9, F1:G5 store below values:

ProductType
AppleRed Delicious
AppleGranny Smith
OrangeValencia
OrangeClementine

<colgroup><col><col></colgroup><tbody>
</tbody>

H1:I1 store values:
1st2nd

<tbody>
</tbody>

Enter below formula in H2(Ctrl+Shift+Enter for the array formula) and copy to range H2:I5:

Code:
=INDEX($A:$A,MOD(LARGE(IF(($B$2:$B$9=$F2)*($C$2:$C$9=$G2),$D$2:$D$9*10^4+ROW(B$2:B$9)),COLUMN(A1)),10^4))
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,109
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top