Limit formula to first 10 times a one criteria is found in a range?

jack109

Board Regular
Joined
May 10, 2020
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi all

Is there a way various formulas (AVERAGEIF, SUMIF, COUNTIF etc) can be used so that they only include the last 10 times the one of the criteria's is found?

For example

The main criteria to use is APPLES

=COUNTIFS(A:A,"APPLES",B:B,"YES")

Apples could appear 30 times in column A but I only want column B to count "YES" first 10 times that "APPLES" appear in column A. The newest data will always at the top of column A.


Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the forum,

I'm sure you will get a better solution, but this appears to work

=IFERROR(COUNTIFS(INDIRECT("A1:A"&INDEX(ROW(A1:A50),SMALL(IF((A1:A50="Apples")*(B1:B50="Yes"),ROW(A1:A50)),10))),"Apples",INDIRECT("B1:B"&INDEX(ROW(A1:A50),SMALL(IF((A1:A50="Apples")*(B1:B50="Yes"),ROW(A1:A50)),10))),"Yes"),COUNTIFS(A1:A50,"APPLES",B1:B50,"YES"))

Enter as an array using Ctrl, Shift & Enter
 
Upvote 0
If you are only using Count, then try this

=MIN(10,COUNTIFS(A:A,"APPLES",B:B,"YES"))
 
Upvote 0
For sumif

=SUMIFS(INDIRECT("c1:c"&INDEX(ROW(A1:A50),SMALL(IF((A1:A50="Apples")*(B1:B50="Yes"),ROW(A1:A50)),10))),INDIRECT("A1:A"&INDEX(ROW(A1:A50),SMALL(IF((A1:A50="Apples")*(B1:B50="Yes"),ROW(A1:A50)),10))),"Apples",INDIRECT("B1:B"&INDEX(ROW(A1:A50),SMALL(IF((A1:A50="Apples")*(B1:B50="Yes"),ROW(A1:A50)),10))),"Yes")

Again enter as an array
 
Upvote 0
Thanks for the reply

Sorry, only tried the first formula and its not producing the results I expect. It is returning 10 for apples when I know the result should be 1.
 
Upvote 0
Yes, Im trying count at the moment.

From the example below "APPLES" appears 15 times. However, the first ten times "APPLES" appears, only 3 times does it match "YES" in column B. The result I am getting is 5, which is the total times "APPLES" and "YES" match.

excel.jpg
 
Upvote 0
I misunderstood & looked for the last 10 with Apple & Yes.

Try
In a new cell enter the following, as an array formula

=INDEX(ROW(A:A),SMALL(IF((A:A="Apples"),ROW(A:A)),MIN(10,COUNTIFS(A:A,"APPLES"))))

This will give the row no. of the 10th match

Then enter this to give the count

=COUNTIFS(INDIRECT("A1:A"&G4),"Apples",INDIRECT("B1:B"&G4),"Yes")

G4 is the cell that i have the array formula in, change it to the cell ref you used
 
Upvote 0
I wouldn't even attempt that with a single formula,
Book1
ABCDE
1PEARSNOCriteria 1APPLES
2APPLESNOCriteria 2YES
3PEARSNOLimit10
4PEARSNOLast row33
5ORANGESYESResult5
6PEARSYES
7APPLESYES
8PEARSNO
9ORANGESNO
10PEARSNO
11APPLESNO
12APPLESYES
13PEARSNO
14APPLESNO
15PEARSYES
16ORANGESNO
17PEARSYES
18PEARSNO
19PEARSNO
20APPLESNO
21PEARSYES
22PEARSNO
23ORANGESNO
24APPLESYES
25ORANGESNO
26PEARSNO
27PEARSYES
28ORANGESYES
29ORANGESYES
30APPLESNO
31ORANGESNO
32APPLESYES
33APPLESYES
34ORANGESYES
35PEARSNO
36APPLESNO
37APPLESNO
38APPLESYES
39PEARSYES
40ORANGESNO
41APPLESYES
42ORANGESNO
43PEARSYES
44ORANGESNO
45PEARSYES
46ORANGESYES
47APPLESYES
48APPLESYES
49APPLESNO
50ORANGESNO
51PEARSYES
52PEARSNO
53APPLESNO
54PEARSYES
Sheet10
Cell Formulas
RangeFormula
E4E4=AGGREGATE(15,6,ROW(A1:A54)/(A1:A54=E1),E3)
E5E5=COUNTIFS(A1:INDEX(A:A,E4),E1,B1:INDEX(B:B,E4),E2)
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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