Dynamic Top N List with SUMIFS

Trepidatioussaurus

New Member
Joined
Oct 12, 2022
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Good day everyone,

I've searched several forums but couldn't find an answer to my question. Maybe it's not even possible in Excel but we'll see...


So, I've got my table with three columns Region, Shoe Size and Sales. What I want to achieve is to create a Top N list of shoe sizes and their corresponding sum of sales. For region A, this would be sizes 45 and 44. Should another region be selectet, also the Top 2 sizes might change, like 44 and 43 for region C:

Excelample.JPG


I was not able to set up this highly dynamic Top 2 list with my Excel version Professional Plus 2016.

A solution without using pivot table is what I would need.

Is this even possible?

Thanks in advance for your replies!

Kind regards
Stefan
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi & welcome to MrExcel.

Can you post your actual data, rather than an image.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Hi & Welcome to MrExcel

Try

Book2
ABCDEFGHIJKL
1ReegionShoe SizeSalesRegionARegionC
2A435Top 2Shoe SizeSum SalesTop 2Shoe SizeSum Sales
3B44101453014425
4C43152441524315
5D4520
6E4610
7A4415
8E435
9F4210
10B4315
11C4425
12A4530
13D4610
14
15
16
Sheet2
Cell Formulas
RangeFormula
F3:F4F3=AGGREGATE(14,6,$B$2:$B$13/($A$2:$A$13=$F$1),E3)
G3:G4G3=SUMIFS(C:C,A:A,$F$1,B:B,F3)
J3:J4J3=AGGREGATE(14,6,$B$2:$B$13/($A$2:$A$13=$J$1),I3)
K3:K4K3=SUMIFS(C:C,A:A,$J$1,B:B,J3)
 
Upvote 0
Hi Sufiyan,

Thanks for introducing me to the aggregate function! I'll use that more often... Unfortunately, my example wasn't the best. For instance, if I change the region for shoe size 46 - highlighted in yellow - to "A", I get 46 as top value, whilst it should be 45 still (top by sum of sales).

Also, how could this work with string values, e.g. every number is preceeded by letter "X"?

Mappe1.xlsx
ABCDEFGHIJK
1RegionARegionC
2
3RegionShoe SizeSalesTop 2Shoe SizeSum SalesTop 2Shoe SizeSum Sales
4A4351453014425
5B44102441524315
6C4315dynamicdynamic
7D4520
8E4610
9A4415RegionARegionC
10E435
11F4210Top 2Shoe SizeSum SalesTop 2Shoe SizeSum Sales
12B43151461014425
13C44252453024315
14A4530
15A4610
16
Tabelle1
Cell Formulas
RangeFormula
F12:F13F12=AGGREGATE(14,6,$B$4:$B$15/($A$4:$A$15=$F$9),E12)
G12:G13G12=SUMIFS(C:C,A:A,$F$9,B:B,F12)
J12:J13J12=AGGREGATE(14,6,$B$4:$B$15/($A$4:$A$15=$J$9),I12)
K12:K13K12=SUMIFS(C:C,A:A,$J$9,B:B,J12)
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJK
1RegionARegionC
2
3RegionShoe SizeSalesTop 2Shoe SizeSum SalesTop 2Shoe SizeSum Sales
4A4351453014425
5B44102441524315
6C4315
7D4520
8E4610
9A4415
10E435
11F4210
12B4315
13C4425
14A4530
15A4610
16
Main
Cell Formulas
RangeFormula
F4:F5F4=INDEX($B$4:$B$100,AGGREGATE(15,6,(ROW($B$4:$B$100)-ROW($B$4)+1)/($A$4:$A$100=$F$1)/($C$4:$C$100=G4),COUNTIFS(G$4:G4,G4)))
G4:G5G4=AGGREGATE(14,6,$C$4:$C$100/($A$4:$A$100=$F$1),ROWS(G$4:G4))
J4:J5J4=INDEX($B$4:$B$100,AGGREGATE(15,6,(ROW($B$4:$B$100)-ROW($B$4)+1)/($A$4:$A$100=$J$1)/($C$4:$C$100=K4),COUNTIFS(K$4:K4,K4)))
K4:K5K4=AGGREGATE(14,6,$C$4:$C$100/($A$4:$A$100=$J$1),ROWS(G$4:G4))
 
Upvote 0
HI Trepidatioussaurus

I think the reason why you are getting 46 instead of 45, is that on your original post, on the last row you had D in the region Column not A. So,Sufiyan97 solution is valid.

Try this with an "X" infront.
Book1
BCDEFGH
2AX435A
3BX441014530
4CX431524415
5DX4520
6EX4610
7AX4415
8EX435
9FX4210
10BX4315
11CX4425
12AX4530
13DX4610
Sheet1
Cell Formulas
RangeFormula
G3:G4G3=RIGHT(INDEX($C$2:$C$13,AGGREGATE(14,6,ROW($C$2:$C$13)-ROW($C$1)/($B$2:$B$13=$G$2),F3)),2)
H3H3=SUMPRODUCT(--(RIGHT(C2:C13,2)=G3)*($B$2:$B$13=$G$2)*(D2:D13))
H4H4=SUMPRODUCT(--(RIGHT(C2:C13,2)=G4)*($B$2:$B$13=$G$2)*(D2:D13))
 
Upvote 0
@Skybluekid I think that you are missing the point. It is the top 2 based on the sales NOT the shoe size.
 
Upvote 0
Hi Skybluekid and Fluff,

Thanks to both of you for your suggestions how to solve my problem. With the example I provided, Fluffs solution worked like a charm!
Unfortunately, my example was flawed in that it has unique values for any combination of region and shoe size. But what if there are several rows with identical regions and shoe sizes and sometimes even sales. That might be the case when adding a dimension like Month but I want to show Top list for the whole year.
I know this changes the demand but this is the hump I couldn't get over.
Mappe1.xlsx
ABCDEFGHIJKL
1RegionARegionA
2desired result
3MonthRegionShoe SizeSalesTop 4Shoe SizeSum SalesTop 4Shoe SizeSum Sales
4JanAX4351X45301X4335
5FebAX44152X44152X4530
6MarAX45303X43153X4415
7MarAX43154X43154X4610
8AprAX4315
9MarAX4610
10JanBX4410
11FebBX4315
12AprCX4315
13MarCX4425
14JanDX4520
15FebEX4610
16JanEX435
17FebFX4210
Tabelle1
Cell Formulas
RangeFormula
G4:G7G4=INDEX($C$4:$C$102,AGGREGATE(15,6,(ROW($C$4:$C$102)-ROW($C$4)+1)/($B$4:$B$102=$G$1)/($D$4:$D$102=H4),COUNTIFS(H$4:H4,H4)))
H4:H7H4=AGGREGATE(14,6,$D$4:$D$102/($B$4:$B$102=$G$1),ROWS(H$4:H4))
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHI
1RegionA
2
3MonthRegionShoe SizeSalesTop 4Shoe SizeSum Sales
4JanAX435351X4335
5FebAX4415152X4530
6MarAX4530303X4415
7MarAX4315 4X4610
8AprAX4315 
9MarAX461010
10JanBX441010
11FebBX431515
12AprCX431515
13MarCX442525
14JanDX452020
15FebEX461010
16JanEX4355
17FebFX421010
18
Main
Cell Formulas
RangeFormula
H4:H7H4=INDEX($C$4:$C$102,AGGREGATE(15,6,(ROW($C$4:$C$102)-ROW($C$4)+1)/($B$4:$B$102=$H$1)/($E$4:$E$102=I4),COUNTIFS(I$4:I4,I4)))
I4:I7I4=AGGREGATE(14,6,$E$4:$E$102/($B$4:$B$102=$H$1),ROWS(I$4:I4))
E4:E17E4=IF(COUNTIFS(C$4:C4,C4,B$4:B4,B4)=1,SUMIFS(D:D,B:B,B4,C:C,C4),"")
 
Upvote 0
Solution

Forum statistics

Threads
1,223,723
Messages
6,174,111
Members
452,544
Latest member
aush

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