[Solved] How to count occurrences of an item in a list?

I’m trying to know how many times is an item repeated in a list. I’ll appreciate any kind of help. Thanks!

Create a helper variable “x”

Throw the list into a list loop “for each item in list j” block.

Use logic in the loop

If j = “text input”

Change var x by 1

Else

Continue to next iteration

Now, X should equal the number of duplicates any given item you put into “text input”

Thanks! But I don’t want to compare it to a text input, but to itself. So would it be if J = J?

Good thinking, but No. That will always equal true. Are you trying to find the number of duplicates for each item. Or is the list only composed of 1 item, simply repeated multiple times.

Perhaps some extra info about what you are trying to accomplish plus be helpful?

Sure. So I have an AirTable with 2 columns. Column #1 is for Task and Column #2 is for Date. So basically I want to know how many tasks I have for ‘x’ date, so I need to know how many times is ‘x’ is repeated. Hope you understand! Thanks by the way! :smile:

It’s important to say I don’t want to manually search for repeated items. Instead, I want the app to automatically search for dates that have more than 3 tasks assigned and alert the user. (There can not be more than 3 tasks for one date).

For example: If user adds a task for tomorrow and there are already 3 tasks for tomorrow, then tell the user there are already 3 tasks for tomorrow!

Why are you organizing your tasks like this?

Column 1_______Column 2
Take out trash____2/20/20
Wash dishes_____2/20/20

When you could instead organize them like this:

Column 1_____Column 2_________Column 3
2/20/20_______Take out trash_____Wash dishes

If you have all of the tasks for a single date in a single row then you just count the length of the row or find the first blank cell and then you know how many tasks you have.

I get what you are saying, but it would make things weird and messy! Thanks anyway!

It sounds like you can ignore the task column, right? You just need to count the number of times a specific date appears in one column. That shouldn’t be too hard.

This should work although when I Live Test it, it returns twice the value it should (6 instead of 3):

Screen Shot 2020-02-20 at 5.24.41 PM

I used this Airtable spreadsheet:

Screen Shot 2020-02-20 at 5.27.12 PM

2 Likes

Thank you very much! I will try different things!

1 Like