VLookup largest 4 values

Okki1

New Member
Joined
Jun 3, 2016
Messages
3
Hey guys,

I have a question regarding the following situation. I have an excel file with over 35.000 rows with a similar situation like this:

In the first part are all the sales for different companies, and I would like to find the sum of the top 4 sales of each individual company. Thus, the formula should be put where the dots are, and should calculate the sumo the largest 4 sales number in the second column. Some items (i.e., 7000 companies) in my dataset have over 50 rows of data, and I am only interested in the largest 4 for one part my thesis.

Example:

CompanySalesCompanyTop 4 sales
11001...
22002
...
43003...
24004...
3500
1500
4500
2400
4300
1200

<tbody>
</tbody>


I have tried several options, but I cannot get it done. Thanks in advance! :)
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
What have you tried that doesn't work?

What do you mean by "the largest 4"? Do the company numbers in the third column correspond to the company numbers in the first, or do they denote the top four performing companies? If the latter, how is that determined? Is it based on just their top four sales, or is it based on all of their sales (but you want the sum of just their top four)?

There is a lot here that seems ambiguous to me.
 
Upvote 0
=SUMPRODUCT(LARGE(($A$2:$A$11=$D2)*($B$2:$B$11),{1,2,3,4}))

Where your company range is A2:A11 your Sales range is B2:B11 and your Company 1 is positioned in cell D2.

This gives (when autofilled)

1 800
2 1000
3 500
4 1100
 
Last edited:
Upvote 0
I have tried variations of VLOOKUP and IF, combined with LARGEST.

The numbers in the first and third column just corresponds (but the amount is large, i.e., > 7000). But the numbers in the first column are mixed, third column is arranged. The value in the fourth column should, thus, be the sum of the largest 4 sale numbers for each company.

In the thesis these aren't companies but industry segments. I need the top 4 sales for each firm to determine the concentration of each segment (i.e., top 4 / total sales). You get it?
 
Upvote 0
try


Excel 2012
ABCDEFGH
1CompanySalesCompany/Top1234
211501440400400400
324202490490470440
432403390350340240
543304460440330300
6190
72490
83120
94460
101400
11220
12370
13430
141440
152470
163390
174110
181260
192280
203340
214440
221350
232440
243350
254300
261400
272330
283210
294180
301400
312490
Sheet4
Cell Formulas
RangeFormula
E2=SUMPRODUCT(LARGE(($A$2:$A$991=$D2)*($B$2:$B$991),E$1))
 
Upvote 0
Both formula give #N/A as a result. Is this because there are #N/A values in the "Company" column that should be deleted first?
 
Upvote 0
Sort column B (Sales) from largest to smallest

ABCDEFGH
CompanySalesCompanyCount1st2nd3rd4th
1350013500200100
2150023400400200
3450031500
4240043500300300
52400
64300
74300
82200
91200
101100

<colgroup><col width="64" style="width:48pt"> <col width="64" span="4" style="width:48pt"> <col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>


D2:
=COUNTIFS($A$2:$A$11,C2)

E2:
=IF(COLUMNS($E2:E2)<=$D2,INDEX($B$2:$B$11,SMALL(IF($A$2:$A$11=$C2,
ROW($A$2:$A$11)-ROW($A$2)+1),COLUMNS($E2:E2))),"") --> to be enterred as array formula (Ctrl+Shift+Enter, if done correctly { } brackets will appear.

Then simply drag D2 down and E2 right and down up until the amount of values you want to display
 
Upvote 0
Hi Okki,

Assuming you've got 'Company' in cell A1 and no spacers in between the columns, try this formula in the first dotted cell under 'Top 4 Sales' (cell D2) . Instead of pressing return to enter it, press Ctrl + Shift + Return to make it an array formula.

=IFERROR(SUM(LARGE(IF($A$2:$A$36=$C2,$B$2:$B$36,""),1),LARGE(IF($A$2:$A$36=$C2,$B$2:$B$36,""),2),LARGE(IF($A$2:$A$36=$C2,$B$2:$B$36,""),3),LARGE(IF($A$2:$A$36=$C2,$B$2:$B$36,""),4)),"")

There's probably a more elegant solution, but this works. It'll only show a value where a company has four or more values to count. If you want it to work so that it counts all available values if less than four available, I'd recommend splitting the formula into its separate IFERROR(LARGE(IF())) components, in columns D E F and G to get your four separate highest values in order, then summing them in column H.

Hope that helps
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

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