Return most frequent text strings with a filter/if statement

effdeearr

New Member
Joined
Feb 20, 2021
Messages
3
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

So, I have a list of data. For these purposes my data is all text strings.

Is there a way I can use a formula to return the top 3 most frequent strings in a column, while also using an IF statement (or similar) to include only a subset of the overall dataset?

I'll use an example:

CategoryFilter
Item 1B
Item 1B
Item 1B
Item 2A
Item 2B
Item 4A
Item 4A
Item 4B
Item 4B

I know that I can use formulae to return the most frequent strings from the category column. I've used a formula found online (as it happens I know the formula works but can't claim to fully understand how it works):

Using
=OFFSET($A$1,MODE(MATCH($A$2:$A$40,$A$2:$A$40,0)),0)
In an initial cell, then
=OFFSET($A$1,MODE(IF(COUNTIF($D$1:$D1,$A$2:$A$40)=0,MATCH($A$2:$A$40,$A$2:$A$40,0)+{0,0})),0)
and
=OFFSET($A$1,MODE(IF(COUNTIF($D$1:$D2,$A$2:$A$40)=0,MATCH($A$2:$A$40,$A$2:$A$40,0)+{0,0})),0)
etc
[I would be interested to know if anyone can actually explain to me what this formula is doing?]

I can't find a way to use a formula / nest a function into this formula that would then only return the most frequent entries that also are only in Filter B, or Filter A, for example.

I've tried to upload a mini-sheet but not sure if it'll work.

Sincerely

EffDeeArr

Book4.xlsx
ABCDE
1StringFilterTelephone211
2Telephone11Telephone411
3Telephone12Telephone35
4Telephone12Telephone13
5Telephone101Telephone101
6Telephone111Telephone111
7Telephone121Telephone121
8Telephone131
9Telephone21
10Telephone21
11Telephone21
12Telephone21
13Telephone21
14Telephone21
15Telephone21
16Telephone21
17Telephone21
18Telephone21
19Telephone21
20Telephone31
21Telephone31
22Telephone31
23Telephone31
24Telephone31
25Telephone41
26Telephone41
27Telephone41
28Telephone41
29Telephone41
30Telephone41
31Telephone41
32Telephone41
33Telephone41
34Telephone41
35Telephone41
36Telephone51
37Telephone61
38Telephone71
39Telephone81
40Telephone91
41
42
Sheet1
Cell Formulas
RangeFormula
D1D1=OFFSET($A$1,MODE(MATCH($A$2:$A$40,$A$2:$A$40,0)),0)
E1:E7E1=COUNTIFS(A:A,D1)
D2:D7D2=OFFSET($A$1,MODE(IF(COUNTIF($D$1:$D1,$A$2:$A$40)=0,MATCH($A$2:$A$40,$A$2:$A$40,0)+{0,0})),0)
Press CTRL+SHIFT+ENTER to enter array formulas.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Is this what you're trying to do?
Book1 (version 1)19.2.21.xlsx
ABCDE
1StringFilterTelephone44
2Telephone1CTelephone22
3Telephone1CTelephone71
4Telephone1BTelephone81
5Telephone10C
6Telephone11D
7Telephone12B
8Telephone13D
9Telephone2C
10Telephone2B
11Telephone2B
12Telephone2A
13Telephone2C
14Telephone2D
15Telephone2C
16Telephone2B
17Telephone2D
18Telephone2D
19Telephone2A
20Telephone3B
21Telephone3B
22Telephone3B
23Telephone3D
24Telephone3C
25Telephone4D
26Telephone4A
27Telephone4A
28Telephone4C
29Telephone4C
30Telephone4C
31Telephone4A
32Telephone4B
33Telephone4D
34Telephone4B
35Telephone4A
36Telephone5C
37Telephone6D
38Telephone7A
39Telephone8A
40Telephone9D
Sheet14
Cell Formulas
RangeFormula
D1:E4D1=SORT(CHOOSE({1,2},UNIQUE(FILTER(A2:A40,B2:B40="A")),COUNTIFS(A2:A40,UNIQUE(FILTER(A2:A40,B2:B40="A")),B2:B40,"A")),2,-1)
Dynamic array formulas.
 
Upvote 0
Solution
If you have the LET function with 365, another option
+Fluff 1.xlsm
ABCDEFGH
1StringFilter
2Telephone1CFilterATelephone44
3Telephone1ERows3Telephone22
4Telephone1BTelephone71
5Telephone10C
6Telephone11D
7Telephone12B
8Telephone13D
9Telephone2C
10Telephone2B
11Telephone2B
12Telephone2A
13Telephone2C
14Telephone2D
15Telephone2C
16Telephone2B
17Telephone2D
18Telephone2D
19Telephone2A
20Telephone3B
21Telephone3B
22Telephone3B
23Telephone3D
24Telephone3C
25Telephone4D
26Telephone4A
27Telephone4A
28Telephone4C
29Telephone4C
30Telephone4C
31Telephone4A
32Telephone4B
33Telephone4D
34Telephone4B
35Telephone4A
36Telephone5C
37Telephone6D
38Telephone7A
39Telephone8A
40Telephone9D
Master
Cell Formulas
RangeFormula
G2:H4G2=LET(Uni,UNIQUE(FILTER(A2:A40,B2:B40=E2)),INDEX(SORT(CHOOSE({1,2},Uni,COUNTIFS(A:A,Uni,B:B,E2)),2,-1),SEQUENCE(MIN(COUNTA(Uni),E3)),{1,2}))
Dynamic array formulas.
 
Upvote 0
Is this what you're trying to do?
Book1 (version 1)19.2.21.xlsx
ABCDE
1StringFilterTelephone44
2Telephone1CTelephone22
3Telephone1CTelephone71
4Telephone1BTelephone81
5Telephone10C
6Telephone11D
7Telephone12B
8Telephone13D
9Telephone2C
10Telephone2B
11Telephone2B
12Telephone2A
13Telephone2C
14Telephone2D
15Telephone2C
16Telephone2B
17Telephone2D
18Telephone2D
19Telephone2A
20Telephone3B
21Telephone3B
22Telephone3B
23Telephone3D
24Telephone3C
25Telephone4D
26Telephone4A
27Telephone4A
28Telephone4C
29Telephone4C
30Telephone4C
31Telephone4A
32Telephone4B
33Telephone4D
34Telephone4B
35Telephone4A
36Telephone5C
37Telephone6D
38Telephone7A
39Telephone8A
40Telephone9D
Sheet14
Cell Formulas
RangeFormula
D1:E4D1=SORT(CHOOSE({1,2},UNIQUE(FILTER(A2:A40,B2:B40="A")),COUNTIFS(A2:A40,UNIQUE(FILTER(A2:A40,B2:B40="A")),B2:B40,"A")),2,-1)
Dynamic array formulas.

So sorry for the delayed response - especially given how quickly you got back to me. Massive thanks.

I haven't tested it yet (the computer I was doing my checks on is my personal one, with non-365 office on it, but I'll try this again when I'm next on my work machine. The formula definitely looks like it'll do what I'm after though. Will report back.

Again - massive thanks for your response.
 
Upvote 0
If you have the LET function with 365, another option
+Fluff 1.xlsm
ABCDEFGH
1StringFilter
2Telephone1CFilterATelephone44
3Telephone1ERows3Telephone22
4Telephone1BTelephone71
5Telephone10C
6Telephone11D
7Telephone12B
8Telephone13D
9Telephone2C
10Telephone2B
11Telephone2B
12Telephone2A
13Telephone2C
14Telephone2D
15Telephone2C
16Telephone2B
17Telephone2D
18Telephone2D
19Telephone2A
20Telephone3B
21Telephone3B
22Telephone3B
23Telephone3D
24Telephone3C
25Telephone4D
26Telephone4A
27Telephone4A
28Telephone4C
29Telephone4C
30Telephone4C
31Telephone4A
32Telephone4B
33Telephone4D
34Telephone4B
35Telephone4A
36Telephone5C
37Telephone6D
38Telephone7A
39Telephone8A
40Telephone9D
Master
Cell Formulas
RangeFormula
G2:H4G2=LET(Uni,UNIQUE(FILTER(A2:A40,B2:B40=E2)),INDEX(SORT(CHOOSE({1,2},Uni,COUNTIFS(A:A,Uni,B:B,E2)),2,-1),SEQUENCE(MIN(COUNTA(Uni),E3)),{1,2}))
Dynamic array formulas.

Much like I said to the other poster - sorry for the massive delay in response, I really appreciate your quick suggestion. I'll try this out too when I'm next on my work computer with 365.

Thanks again for your response. Truly grateful.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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