sumif large top 5 items

whatever999

New Member
Joined
Mar 5, 2018
Messages
2
Hi,

I have the following data:

DayStateCustomers
1NY500
2NY300
3NY1000
1CA800
1WA900
1OR200
2CA400
2WA3000
3CA2500

<tbody>
</tbody>

I want to rank top 3 cities by customers (regardless of day). Desired result:

Top 1: WA , 3900
Top 2: CA, 3700
Top 3: NY, 1800
Top 4: OR, 200

How can I do that with one formula?

thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Row\Col
A​
B​
C​
D​
E​
F​
G​
1​
DayStateCustomers
5​
2​
1
NY
500
4​
3​
2
NY
300
statecus value
4​
3
NY
1000
WA
3900​
5​
1
CA
800
CA
3700​
6​
1
WA
900
NY
1800​
7​
1
OR
200
OR
200​
8​
2
CA
400
9​
2
WA
3000
10​
3
CA
2500

For the formulas to work, we need to install the V() function using Alt+F11 of which the code is as follows:

Public Function V(Optional vrnt As Variant) As Variant
'
' Stephen Dunn
' 2002-09-12
'
Static vrntV As Variant
If Not IsMissing(vrnt) Then vrntV = vrnt
V = vrntV
End Function

F1 : 5 (desired top N)

In F2 control+shift+enter, not just enter:

=SUM(IF(V(SUMIFS($C$2:$C$10,$B$2:$B$10,IF(FREQUENCY(IF(1-($B$2:$B$10=""),MATCH($B$2:$B$10,$B$2:$B$10,0)),ROW($B$2:$B$10)-ROW($B$2)+1),$B$2:$B$10)))>=LARGE(V(),MIN(F1,SUM(IF(V()>0,1)))),1))

In F4 control+shift+enter, not just enter, and copy down:

=IF($G4="","",INDEX($B$2:$B$10,SMALL(IF(V(SUMIFS($C$2:$C$10,$B$2:$B$10,IF(FREQUENCY(IF(1-($B$2:$B$10=""),MATCH($B$2:$B$10,$B$2:$B$10,0)),ROW($B$2:$B$10)-ROW($B$2)+1),$B$2:$B$10)))=$G4,ROW($B$2:$B$10)-ROW($B$2)+1),COUNTIFS($G$4:G4,G4))))

In G4, control+shift+enter, not just enter, and copy down:

=IF(ROWS($G$4:G4)>$F$2,"",LARGE(SUMIFS($C$2:$C$10,$B$2:$B$10,IF(FREQUENCY(IF(1-($B$2:$B$10=""),MATCH($B$2:$B$10,$B$2:$B$10,0)),ROW($B$2:$B$10)-ROW($B$2)+1),$B$2:$B$10)),ROWS($G$4:G4)))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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