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

Hola!

Days ago I had a strange case, I was working with a Glide table with almost 10k rows and to avoid creating new 3 or 4 columns I decided to create a short JS code to get a result easily (it was going to save me 40k new values!).

Well, after I created my JS code and ran it, the Pape performance was a chaos. Every time I changed a value in that GT, the Page lasted 20-30 sec to respond and show newer data, a headache!

Checking the problem source I found that my JS code was the culprit (well, the JS plugin!). It seemed that my JS code was executed 10k times but I didn’t know where!!.. it looked like an API request waiting a reply doing the same thing 10k times :exploding_head:

In the end, I had to remove it, create 4 Glide native columns (ITE and Template) and hold 40k extra values to get what I wanted and get my previous performance back.
I still don’t understand this strange phenomenon with JS plugin.

If you have any chance to replicate this in one of your GT I’d appreciate it, so far I’m disappoint with this JS plugin for this case.

Thanks!

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: