Summing and Top/Bottom Results

Graemea

Board Regular
Joined
Oct 30, 2015
Messages
116
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have sample data in A:B and would like in columns D:E to extract from this the top and bottom 5 products by total sales.

The results that I would expect from my sample data are shown in D:E in the screenshot below.

The sales for each product is simply the sum of the Sales in column B.

Getting the top and bottom 5 products by total sales can easily by done with a Pivot Table but a formula solution would be far more helpful for my purposes.

Is there a formula that someone could please suggest?

Thanks!

Excel2.PNG
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
One way:

Book5
ABCDE
1ProductSalesTOP 2
2AAA100DDD800
3BBB300BBB600
4CCC200
5DDD400BOTTOM 2
6AAA100AAA200
7BBB300CCC400
8CCC200
9DDD400
10
Sheet12
Cell Formulas
RangeFormula
D2:D3D2=INDEX($A$2:$A$9,MATCH(MAX(IF(COUNTIF($D$1:$D1,$A$2:$A$9)=0,SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9))),IF(COUNTIF($D$1:$D1,$A$2:$A$9)=0,SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9)),0))
E6:E7,E2:E3E2=SUMIF($A$2:$A$9,D2,$B$2:$B$9)
D6:D7D6=INDEX($A$2:$A$9,MATCH(MIN(IF(COUNTIF($D$1:$D5,$A$2:$A$9)=0,SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9))),IF(COUNTIF($D$1:$D5,$A$2:$A$9)=0,SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9)),0))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Can I please ask one more quick question.

Can someone please suggest how the above formulae can be adapted to exclude certain product codes.

For example, if the product code is "GGG" or "MMM", it will be ignored from the determination of the top or bottom 5 products; if a product is excluded, then the next largest, or smallest, will take its place.

Thanks!
 
Upvote 0
Maybe:

Book5
ABCDEFG
1ProductSalesTOP 2Exclude
2AAA100BBB600AAA
3BBB300CCC400DDD
4CCC200
5DDD400BOTTOM 2
6AAA100CCC400
7BBB300BBB600
8CCC200 
9DDD400
Sheet12
Cell Formulas
RangeFormula
D2:D3D2=IFERROR(INDEX($A$2:$A$9,MATCH(MAX(IF((COUNTIF($D$1:$D1,$A$2:$A$9)=0)*ISERROR(MATCH($A$2:$A$9,$G$2:$G$10,0)),SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9))),IF((COUNTIF($D$1:$D1,$A$2:$A$9)=0)*ISERROR(MATCH($A$2:$A$9,$G$2:$G$10,0)),SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9)),0)),"")
E6:E7,E2:E3E2=SUMIF($A$2:$A$9,D2,$B$2:$B$9)
D6:D8D6=IFERROR(INDEX($A$2:$A$9,MATCH(MIN(IF((COUNTIF($D$5:$D5,$A$2:$A$9)=0)*ISERROR(MATCH($A$2:$A$9,$G$2:$G$10,0)),SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9))),IF((COUNTIF($D$5:$D5,$A$2:$A$9)=0)*ISERROR(MATCH($A$2:$A$9,$G$2:$G$10,0)),SUMIF($A$2:$A$9,$A$2:$A$9,$B$2:$B$9)),0)),"")
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


Although Mike has a point. This formula is getting pretty unwieldy. You can make a pivot table in just a few seconds, although I couldn't quite figure out how to get it to sort by the Sum of Sales column.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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