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
8 replies
Sort By: 

Mar 28, 2025 11:45 AM in response to markcq

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.

Reply

Mar 28, 2025 7:47 PM in response to markcq

There will be a problem with this solution if there are two numbers that occur the same number of times. It will give the first number twice instead of giving both of them. For example, if 7 and 11 both occurred 5 times, it will give the results as 7 and 7.


The start of a solution that will not have that issue is to change the column B formula to

=COUNTIF(Table 1::A:B,A1) + ROW()/100


This will get the counts to be unique so that you can get the unique results. I think if you format the "frequency" cells to 0 decimals that might be the only other thing you need to do. Or other formulas could be used in those rows that wouldn't rely on cell formatting to look right.

Reply

Mar 31, 2025 10:12 AM in response to Badunit

Darn - forgot the case where there's a repeating quantity. Good catch.


The other way that might also work is a filter.


With my second table counting 1-22, you could set a filter on column B to show only cells that match 4 or greater. In this way the table dynamically resizes to show all rows with 4 or more. They're in numeric order, though, not size, if that matters.

Reply

Mar 28, 2025 8:44 AM in response to markcq

Do you just need to quickly spot the high frequency numbers, or do you need to perform further calculations on them?


If you just need to spot them, then you could consider something like this, using Conditional Highlighting.


Add additional columns mirroring your original ones, and add this formula:



In C2, filled right and down:


=IF(COUNTIF($A:$B,A2)>=4,A2,"")


Then select the original cells and apply a Conditional Highlighting rule(Format > Cell tab) like this:




To enter the C2 in the Rule you'll need to first click the box-and-arrow icon, then select the cell in the table.


Use cell conditions in Numbers on Mac - Apple Support


COUNTIF - Apple Support


SG





Reply

Mar 28, 2025 1:03 PM in response to Camelot

@Camelot YES! This is amazing! Exactly what I needed. I already have a few sheets with various calculations, so I just added another table to one of the sheets. I don't mind having it visible, but I just locked it. If I'm sharing this with anyone else to work with then I will likely hide the rows to make it less confusing.


Thank you so much. I've been wrecking my brain for a long time to try and figure this one out.

Reply

Mar 29, 2025 4:34 AM in response to Badunit

Badunit wrote:

There will be a problem with this solution if there are two numbers that occur the same number of times. It will give the first number twice instead of giving both of them. For example, if 7 and 11 both occurred 5 times, it will give the results as 7 and 7.

The start of a solution that will not have that issue is to change the column B formula to
=COUNTIF(Table 1::A:B,A1) + ROW()/100

I did a test of this and you're right, it shows the one number twice.


Your solution to works really well. That's a very clever way of doing it!

Reply

Mar 31, 2025 10:34 PM in response to Camelot

Camelot wrote:

The other way that might also work is a filter.

Oh yes! Duh! I completely forgot about filters. I just set up a massive document for a friend of mine so she can create her Live Blood Analysis and then at end turn on the filters to have only the information relevant to the client so she can give them a report.


The tip Badunit gave is very clever and a way to ensure that numbers don't repeat.


You guys rock!

Reply

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.