Count number of instances in a list

I’m looking to count the number of times x word is used in a list and display that information (either on a chart, etc.).

For example:
List = [bob,bob,sara,mary,mary,bob]

I’d like to return:
Bob - 3
Mary - 2
Sara - 1

I want this mechanic to be dynamic for each user, so I can’t apply a filter with a preset value. In other words, I wouldn’t want to build the function like ‘Filter: Text contains “Bob”’ because that text will be different for each user.

Does anyone know how I would do this? I’m not looking to use the “unique words” function since that won’t count the number of times that word is used in the list.

Thank you!

Not sure if I’m understanding correctly but I’ll try answer.

You can display that information in a repeating group using a combination of “unique words” function and filters.

I made an example for you whereby I created a new data type “xDataType” which has a “list of texts” field for your list of names (bob, bob, bob, mary, mary, sara). Like so:

And added your list of names to the field

Then I set up a repeating group with data source: Search for xDataType:first item’s list of names:unique elements

Each cell will now be populated by a unique name and there will be 3 unique names, so 3 cells will be populated (one for bob, one for mary, one for sara).

Now to “count” how many of each unique name there is in your list

I added a text element to the RG and in the dynamic text, I wrote "Current cell’s text:Search for xDataTypes:first item’s list of names:filtered:count

for the filter, I added “this text contains current cell’s text”

The result on preview was as follows:

Is this what you were after?

Nice one @michael40 - i was trying to think of how that could be achieved in Bubble! an example below of both using Javascript or Bubble’s custom states with Michael40’s solution:

count example

This topic was automatically closed after 70 days. New replies are no longer allowed.