Count Exact Word Similar in an array

So lets say we have a joined text returned from a relation as the follow

example1,example2,example2,example1,example3

What I need to achieve is in a table of record

example1 found it 2 times
example2 found it 2 times
example3 found 1 time

It seems that it can be archived by Java script I didn’t yet try it but I wonder if it can be done by glide yes columns if there is

This will help a lot in reporting

Thanks

I have a Custom Code column that will do this, you are welcome to clone it or use it directly.

It accepts 3 parameters:

  • Joined List of values (as per your example)
  • Joined List of Items to search
  • (Optional) Number of Items in the first list to use for the search

To use it for your case, you’d need multiple rows - one for each item in the list you want to count.

Here is how it would look:

And the Code Column configuration:

Note: This code column was written for a completely different use case, so it’s probably overkill for what you want to do. But it will still get the job done.

1 Like

Am using the same method in javascript somehow like the below

let myString = p1;
let mySubString = p2;

let count = myString.split(mySubString).length - 1;
return count; 
```/
what do you think should I use the yes column better or the JS ?
2 Likes

For simple things like this, I think a JavaScript column is fine.

2 Likes

Interesting.

Would you mind sharing the JavaScript snippet that caused this behaviour?

As a general rule, I try to use my own JavaScript (both the plugin and the external code column) sparingly. I’ll usually only write my own code if I can’t find any other way to do it with standard computed columns, or if it will save me a bunch of columns. Also, my JavaScript skills are intermediate at best, so I’d rather place my trust in code written by Glide Engineers than my own :wink:

Let me rewrite it again and retest it with a GT old version that I have.

I will let you know it but the code was harmless :roll_eyes:

BTW, I have my own version for this :wink: