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!

[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Product[/TD]
[TD]Type[/TD]
[TD]Sales[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Apple[/TD]
[TD]Red Delicious[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Apple[/TD]
[TD]Granny Smith[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Orange[/TD]
[TD]Valencia[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Orange[/TD]
[TD]Clementine[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Bob Smith[/TD]
[TD]Apple[/TD]
[TD]Red Delicious[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Bob Smith[/TD]
[TD]Apple[/TD]
[TD]Granny Smith[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]Bob Smith[/TD]
[TD]Orange[/TD]
[TD]Valencia[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]Bob Smith[/TD]
[TD]Orange[/TD]
[TD]Clementine[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

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:

[TABLE="width: 164"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Product[/TD]
[TD]Type[/TD]
[/TR]
[TR]
[TD]Apple[/TD]
[TD]Red Delicious[/TD]
[/TR]
[TR]
[TD]Apple[/TD]
[TD]Granny Smith[/TD]
[/TR]
[TR]
[TD]Orange[/TD]
[TD]Valencia[/TD]
[/TR]
[TR]
[TD]Orange[/TD]
[TD]Clementine[/TD]
[/TR]
</tbody>[/TABLE]

H1:I1 store values:[TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 80"]1st[/TD]
[TD="class: xl65, width: 80"]2nd[/TD]
[/TR]
</tbody>[/TABLE]

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,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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