Find numbers that repeat a certain number of times

I have a table with a few rows and two columns. I'm looking for a way to find numbers that repeat four (4) or more times in the table.


e.g. in the example below I have 22-4, 4-4 and 15-4. I want the 4 to go into the cell in row 9.

Currently I do this manually, which is ok for one spreadsheet, but I do this a number of times a day and it gets a bit tedious. The rest of my spreadsheet is pretty automated with only a few things I have to do manually, like inserting images into cells that I can't do with functions.


I have not yet been able to figure out how to check for these numbers that repeat four (4) or more times.


And if I have a table where there are two numbers that repeat four (4) or more times, then I would have another row for the second number. I guess this complicates matter again, but I guess I could have an if statement to check if the field is empty or if a number is already listed before populating the next cell?


Within this table I only work with numbers 1 – 22. I will never have a zero (0) and never have a number higher than 22... I don't know If that makes things easier at all?

MacBook Pro 14″

Posted on Mar 27, 2025 10:31 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 28, 2025 11:45 AM

I took a similar approach to SGIII, but with a couple of changes.


We both use some intermediate space to work out the frequency (Numbers don't have strong array functions to do this in one step). While SGIII put these calculations in adjacent columns, I opted for a separate table.


I took advantage of the fact that there a cap of 22 values to process.


To that end, I created a table with 23 rows + 2 footer rows (for the results area), and no header rows or columns.

(these row counts are important)


Column A1:A22 is filled with the formula:


=ROW()


which simply returns the row number, and is an easy way to build a list of consecutive numbers.


Column B1:B22 is filled down with the formula:


=COUNTIF(Table 1::A:B,A1)


This counts the number of entries in Table1::A:B (columns A and B of the values table) that match the current row's number.


Now I have a simple table that counts each of the possible numbers 1 through 22:



Once we're done, we can hide the 22 rows in the Table 2 since we don't need to see them, but they're there for clarity right now.


Then I added two footer rows to Table 2. These will be used to callout the entries with a frequency ≥4.


In cell A24, I set the formula to:


=LARGE(B,1)


this returns the largest number in the column. Similarly,A25 is set to:


=LARGE(B,2) which returns the second-largest value (used for the second place score).


You can add more if you need them, up to 5 footer rows.


Now we can see the quantities that occur 4 or more times, so it's time to work out what they actually are.


In cell B24, the formula is:


=IF(A$24≥4,XLOOKUP(LARGE(B,1),B,A,"",0,1),"")


decoding this, we first check to see if A$24 is ≥ 4. If it is, we perform a XLOOKUP() where we search for the LARGE()st number in column B and return the corresponding value from column A (which, if you recall, is the sequential counter). No matches, or if A$24 <4 returns an empty cell.


Repeating this in cell B25, just change the LARGE(B,1) to LARGE(B, 2) to get the second largest value, etc.


This gives me something like:



Where A24 shows me that we have some value with 5 occurrences, and A25 reports something with 4. B24/25 then perform the lookup to return the actual values we want.


Now, we can hide rows 1-22 and format the table such that it integrates with the main table:




Note, Table 2 has rows 1:22 hidden, and is positioned below the main table - you could even close the gap if you want it to look like it's part of the same table.

You can also set the display of cells A24 and A25 to hide the frequency value if you don't want to see it.

21 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Find numbers that repeat a certain number of times

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.