Find values in a range and Sum only the last N

IvanMarkus

New Member
Joined
Jun 6, 2015
Messages
6
Hi Community!


1-I want to find values in a range that is equal to one cell.
2-Sum the values of the another column that matches with found. But I just want to add the N (4,5,6, ...) last.


With the function SUMIF I get to do the first part, but I add up all the values found.
SUMAIF($B$2:$B137,B138,$C$2:$C137)


I need sum only the last 6 values found.


I do not know how to control the number of summands max to include in the SUM function.


Any suggestions?

DateColumnaAImporte
09/12/2000A23000456
09/12/2000B34000789
09/12/2000H25000123
09/12/2000O12000258
09/12/2000T47000147
09/12/2000R45678369
09/12/2000HU8900963
09/12/2000KP4098852
10/12/2000TR3409741
10/12/2000E35000456
16/12/2000A23000654
16/12/2000B34000987
16/12/2000E35000321
16/12/2000H25000456
16/12/2000HU8900789
16/12/2000KP4098123
16/12/2000O12000258
16/12/2000R45678147
17/12/2000T47000369
18/12/2000TR3409963
22/12/2000B34000852
23/12/2000HU8900741
23/12/2000KP4098456
23/12/2000T47000654
23/12/2000TR3409987
23/12/2000O12000321
23/12/2000R45678456
23/12/2000H25000789
23/12/2000A23000123
23/12/2000E35000258
26/12/2000TR3409147
26/12/2000T47000369
26/12/2000R45678963
26/12/2000O12000852
26/12/2000KP4098741
26/12/2000HU8900456
26/12/2000H25000654
26/12/2000E35000987
26/12/2000B34000321
27/12/2000A23000456
30/12/2000A23000789
30/12/2000B34000123
30/12/2000H25000258
30/12/2000O12000147
30/12/2000T47000369
30/12/2000R45678963
01/01/2001HU8900852
01/01/2001KP4098741
01/01/2001TR3409456
01/01/2001E35000654
01/01/2001A23000987
01/01/2001B34000321
01/01/2001E35000456
01/01/2001H25000789
01/01/2001HU8900123
02/01/2001KP4098258
13/01/2001O12000147
13/01/2001R45678369
13/01/2001T47000963
13/01/2001TR3409852
13/01/2001B34000741
13/01/2001HU8900456
13/01/2001KP4098654
13/01/2001T47000987
13/01/2001TR3409321
14/01/2001O12000456
20/01/2001R45678789
20/01/2001H25000123
20/01/2001A23000258
20/01/2001E35000147
20/01/2001TR3409369
20/01/2001T47000963
20/01/2001R45678852
20/01/2001O12000741
21/01/2001KP4098456
22/01/2001HU8900654
24/01/2001H25000987
30/01/2001E35000321
30/01/2001B34000456
31/01/2001A23000789
31/01/2001B34000123
31/01/2001H25000258
31/01/2001O12000147
31/01/2001T47000369
31/01/2001R45678963
31/01/2001HU8900852
03/02/2001KP4098741
03/02/2001TR3409456
03/02/2001E35000654
03/02/2001A23000987
03/02/2001B34000321
03/02/2001E35000456
03/02/2001H25000789
03/02/2001HU8900123
03/02/2001KP4098258
07/02/2001O12000147
10/02/2001R45678369
10/02/2001T47000963
10/02/2001TR3409852
10/02/2001B34000741
10/02/2001HU8900456
10/02/2001KP4098654
10/02/2001T47000987
10/02/2001TR3409321
11/02/2001O12000456
12/02/2001R45678789
24/02/2001H25000123
24/02/2001A23000258
24/02/2001E35000147
24/02/2001TR3409369
24/02/2001T47000963
24/02/2001R4567848
24/02/2001O12000741
24/02/2001KP4098456
25/02/2001HU8900654
03/03/2001H25000987
03/03/2001E35000321
03/03/2001B34000456
03/03/2001A23000789
03/03/2001A23000123
03/03/2001B34000258
03/03/2001H25000147
03/03/2001O12000369
04/03/2001T47000963
05/03/2001R45678852
07/03/2001HU8900741
10/03/2001KP4098456
17/03/2001TR3409654
17/03/2001E35000987
17/03/2001A23000321
17/03/2001B34000456
17/03/2001E35000789
17/03/2001H25000123
17/03/2001HU8900258
17/03/2001KP4098147
18/03/2001O12000369
18/03/2001R45678963

<colgroup><col width="80" style="width:60pt"> <col width="80" style="width:60pt"> <col width="80" style="width:60pt"> </colgroup><tbody>
</tbody>


 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
To sum the last 6 values based on a condition, where E2 contains the value of interest (ie. A23000), try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

=SUM(IF(ROW($B$2:$B$138)>=LARGE(IF($B$2:$B$138=E2,ROW($B$2:$B$138)),6),IF($B$2:$B$138=E2,$C$2:$C$138)))

Note, the formula returns the error value #NUM! when there are less than 6 values that meet the condition.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,203,236
Messages
6,054,298
Members
444,715
Latest member
GlitchHawk

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