Return Top 20 On Certain Criteria

Lewzerrrr

Active Member
Joined
Jan 18, 2017
Messages
256
Hi,

I have a data dump in 1 sheet with 20+ departments that I need to pull the top 20 bestsellers for each.

I can do an array formula using INDEX SMALL IF ROW-ROW ROWS however that only pulls if the data is sorted so do I need to incorporate LARGE into this somehow?

Example based on top 3.

[TABLE="width: 512"]
<colgroup><col span="8"></colgroup><tbody>[TR]
[TD][/TD]
[TD="colspan: 2"]Finished Result[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Data Dump[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD]Dept1[/TD]
[TD]Line5[/TD]
[TD="align: right"]6121[/TD]
[TD][/TD]
[TD]Dept1[/TD]
[TD]Line1[/TD]
[TD="align: right"]5435[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]Dept1[/TD]
[TD]Line4[/TD]
[TD="align: right"]5830[/TD]
[TD][/TD]
[TD]Dept1[/TD]
[TD]Line2[/TD]
[TD="align: right"]4675[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD]Dept1[/TD]
[TD]Line1[/TD]
[TD="align: right"]5435[/TD]
[TD][/TD]
[TD]Dept1[/TD]
[TD]Line3[/TD]
[TD="align: right"]4794[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD]Dept2[/TD]
[TD]Line8[/TD]
[TD="align: right"]9372[/TD]
[TD][/TD]
[TD]Dept1[/TD]
[TD]Line4[/TD]
[TD="align: right"]5830[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD]Dept2[/TD]
[TD]Line6[/TD]
[TD="align: right"]7102[/TD]
[TD][/TD]
[TD]Dept1[/TD]
[TD]Line5[/TD]
[TD="align: right"]6121[/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD]Dept2[/TD]
[TD]Line10[/TD]
[TD="align: right"]5270[/TD]
[TD][/TD]
[TD]Dept2[/TD]
[TD]Line6[/TD]
[TD="align: right"]7102[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD]Dept3[/TD]
[TD]Line14[/TD]
[TD="align: right"]7219[/TD]
[TD][/TD]
[TD]Dept2[/TD]
[TD]Line7[/TD]
[TD="align: right"]2965[/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD]Dept3[/TD]
[TD]Line12[/TD]
[TD="align: right"]5000[/TD]
[TD][/TD]
[TD]Dept2[/TD]
[TD]Line8[/TD]
[TD="align: right"]9372[/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD]Dept3[/TD]
[TD]Line13[/TD]
[TD="align: right"]3247[/TD]
[TD][/TD]
[TD]Dept2[/TD]
[TD]Line9[/TD]
[TD="align: right"]4447[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept2[/TD]
[TD]Line10[/TD]
[TD="align: right"]5270[/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept3[/TD]
[TD]Line11[/TD]
[TD="align: right"]1181[/TD]
[/TR]
[TR]
[TD="align: right"]12[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept3[/TD]
[TD]Line12[/TD]
[TD="align: right"]5000[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept3[/TD]
[TD]Line13[/TD]
[TD="align: right"]3247[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept3[/TD]
[TD]Line14[/TD]
[TD="align: right"]7219[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dept3[/TD]
[TD]Line15[/TD]
[TD="align: right"]1745[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Here's one option using formulas:


Excel 2010
ABCDEFG
1Dept1Line56121Dept1Line15435
2Dept1Line45830Dept1Line24675
3Dept1Line15435Dept1Line34794
4Dept2Line89372Dept1Line45830
5Dept2Line67102Dept1Line56121
6Dept2Line105270Dept2Line67102
7Dept3Line147219Dept2Line72965
8Dept3Line125000Dept2Line89372
9Dept3Line133247Dept2Line94447
10Dept2Line105270
11Dept3Line111181
12Dept3Line125000
13Dept3Line133247
14Dept3Line147219
15Dept3Line151745
Sheet1
Cell Formulas
RangeFormula
B1{=INDEX(F$1:F$15,MATCH(A1&C1,E$1:E$15&G$1:G$15,0))}
C1{=LARGE(IF(E$1:E$15=A1,G$1:G$15),COUNTIF(A$1:A1,A1))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Another formula version:

ABCDEFGHI
DepartmentLineAmountDepartmentLineAmount# of lines per department
Dept3Line14Dept3Line13
Dept3Line12Dept1Line2
Dept3Line13Dept2Line8
Dept1Line5Dept3Line12
Dept1Line4Dept3Line14
Dept1Line1Dept2Line9
Dept2Line8Dept1Line3
Dept2Line6Dept2Line10
Dept2Line10Dept2Line7
Dept1Line4
Dept2Line6
Dept1Line1
Dept1Line5
Dept3Line15
Dept3Line11

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]7219[/TD]
[TD="align: right"][/TD]

[TD="align: right"]3247[/TD]
[TD="align: right"][/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]5000[/TD]
[TD="align: right"][/TD]

[TD="align: right"]4675[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]3247[/TD]
[TD="align: right"][/TD]

[TD="align: right"]9372[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]6121[/TD]
[TD="align: right"][/TD]

[TD="align: right"]5000[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]5830[/TD]
[TD="align: right"][/TD]

[TD="align: right"]7219[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]5435[/TD]
[TD="align: right"][/TD]

[TD="align: right"]4447[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]9372[/TD]
[TD="align: right"][/TD]

[TD="align: right"]4794[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]7102[/TD]
[TD="align: right"][/TD]

[TD="align: right"]5270[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]5270[/TD]
[TD="align: right"][/TD]

[TD="align: right"]2965[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]5830[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]7102[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]5435[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]6121[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]15[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]1745[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]16[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]1181[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]A2[/TH]
[TD="align: left"]{=IFERROR(IF(MOD(ROW($A2)-ROW($A$2),$I$2),A1,INDEX(E:E,SMALL(IF(COUNTIF($A$1:$A1,$E$2:$E$16)=0,ROW($E$2:$E$16)),1))),"")}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]B2[/TH]
[TD="align: left"]{=IF(A2="","",INDEX(F:F,SMALL(IF(($E$2:$E$16=A2)*($G$2:$G$16=C2),ROW($F$2:$F$16)),COUNTIFS($A$2:$A2,A2,$C$2:$C2,C2))))}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]C2[/TH]
[TD="align: left"]{=IF(A2="","",LARGE(IF($E$2:$E$16=A2,$G$2:$G$16),MOD(ROW($C2)-ROW($C$2),$I$2)+1))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



I randomly sorted the values in E:G for testing. The formula in A2 finds the unique names from column E, and shows n copies of each, based on the value in I3. You can of course create the list yourself. The formula in B is designed to handle ties as well.
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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