5 largest sums and corresponding value

Nebula2121

New Member
Joined
Apr 1, 2016
Messages
32
Hi. I need help. Example Data in column A - C. Desired Results E-F. I am looking to return the 5 largest sums based on a column and return the corresponding value. Thoughts?

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]FL[/TD]
[TD]200[/TD]
[TD][/TD]
[TD]MN[/TD]
[TD]700[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]TX[/TD]
[TD]200[/TD]
[TD][/TD]
[TD]CO[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]FL[/TD]
[TD]100[/TD]
[TD][/TD]
[TD]FL[/TD]
[TD]400[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]FL[/TD]
[TD]100[/TD]
[TD][/TD]
[TD]TX[/TD]
[TD]400[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]MN[/TD]
[TD]400[/TD]
[TD][/TD]
[TD]CA[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]MA[/TD]
[TD]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]TX[/TD]
[TD]200[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]CA[/TD]
[TD]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]CA[/TD]
[TD]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]CO[/TD]
[TD]500[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]MN[/TD]
[TD]300[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]NY[/TD]
[TD]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
well you could use consolidate to combine all the amounts for each state then sort for high to low. Or use large to obtain top 5 IE =Large(range,1),=Large(range,2)=Large(range,3),=Large(range,4),=Large(range,5)
 
Last edited:
Upvote 0
My first recommendation would be to create a SUMIF table in columns H & I (or wherever).
I'm pretty good with excel formulas, but summing each state and finding the top 5 in one fluid step would be ... "difficult."

Then I would use this to get the "Top 5":
F1 would be =LARGE(I:I,1)
F5 would be =LARGE(I:I,5)
**assuming each state is in column H & each total is in column I

Then I would use ↓this↓ to create your outputs in column E based on the top 5 in column F
Try this...

PS - You can click the arrows next to Valko's name to go to his post in another thread. Just in case you hadn't realized that yet or something.
 
Last edited:
Upvote 0

Book1
BCDEF
1statevalueN5
2FL200state count7
3TX200Nth Value200
4FL100adjusted N5
5FL100statetotal value
6MN400MN700
7MA100CO500
8TX200FL400
9CA100TX400
10CA100CA200
11CO500
12MN300
13NY100
Sheet1


F1: 5 (desired Top N)

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

=SUM(IF(FREQUENCY(IF(1-($B$2:$B$13=""),MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1),1))

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

=LARGE(SUMIFS($C$2:$C$13,$B$2:$B$13,IF(FREQUENCY(IF(1-($B$2:$B$13=""),MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1),$B$2:$B$13)),MIN(F1,F2))

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

=SUM(IF(SUMIFS($C$2:$C$13,$B$2:$B$13,IF(FREQUENCY(IF(1-($B$2:$B$13=""),MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1),$B$2:$B$13))>=F3,1))

This adjusts N for ties if applicable.

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

=IF($F6="","",INDEX($B$2:$B$13,SMALL(IF(SUMIFS($C$2:$C$13,$B$2:$B$13,IF(FREQUENCY(IF(1-($B$2:$B$13=""),MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1),$B$2:$B$13))=$F6,ROW($B$2:$B$13)-ROW($B$2)+1),COUNTIFS($F$6:F6,F6))))

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

=IF(ROWS($F$6:F6)>$F$4,"",LARGE(SUMIFS($C$2:$C$13,$B$2:$B$13,IF(FREQUENCY(IF(1-($B$2:$B$13=""),MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1),$B$2:$B$13)),ROWS($F$6:F6)))
 
Upvote 0
combine.jpg


I used consolidate to create Columns E & F

I used =INDEX($E$2:$F$8,MATCH(LARGE($F$2:$F$8,1),$F$2:$F$8,0),1) in H2 and =LARGE($F$2:$F$8,1) in I2 to show largest state and amount
I used =INDEX($E$2:$F$8,MATCH(LARGE($F$2:$F$8,2),$F$2:$F$8,0),1) in H2 and =LARGE($F$2:$F$8,2) in I3 to show 2nd largest state and amount and so on
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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