Counting repeat entries

I use Cloud

Is there a way to count the number of entries that repeat themselves in a series of rows and then provide a percentage total of unique to repeat entries.

Example:

Dog

Dog

Cat

Chicken

Mouse

would return 20% repeat entries in the list (as dog is repeated twice)

There’s no native feature for your requirement.

But you should be able to produce the desired result using the SQL query plugin. But I failed to come up with an right SQL statement. Maybe others are smarter than me.

Sounds like a challenge! :joy: :joy:

I was able to get both counts using the following SQL query:
SELECT COUNT(DISTINCT `Animals`) AS unique, COUNT(`Animals`) AS whole FROM `Table1`
but not the ratio, so I ended with the following Python script:

from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()

BASE_NAME= 'Table1'
COLUMN_NAME = 'Animals'

count = base.query(f"SELECT COUNT(DISTINCT `{COLUMN_NAME}`) AS unique, COUNT(`{COLUMN_NAME}`) AS whole FROM `{BASE_NAME}`")[0]
ratio = (count["whole"] - count["unique"]) / count["whole"] * 100
print(f"duplicates ratio: {ratio}%")

Bests,
Benjamin

Nice solution. One small addition in case it helps: if you also want to see which values are the repeated ones, a GROUP BY query lists them with their counts:

`` SELECT `Animals`, COUNT(`Animals`) AS cnt FROM `Table1` GROUP BY `Animals` ORDER BY cnt DESC ``

It’s also worth deciding what “repeat entries” should mean. The query above gives 20% for the example because it counts only the extra copies (5 rows, 4 distinct values). If you’d rather count every row that belongs to a duplicated value (both “Dog” rows), the example would come out at 40%, and you’d sum cnt for the groups where cnt > 1 in the script instead.