# Need help in extracting similar names in Lookup response and also get the count of times repeated

**URL:** <https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511>\
**Category:** Ask for Help\
**Created:** [August 8, 2024, 8:23am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511 "2024-08-08T08:23:09Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 8, 2024, 8:23am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/1 "2024-08-08T08:23:09Z")

</div>

Hi Guys,

I have a query which gives me response for number of campaigns for given brand.

I find lookup and get creator names

![Screenshot 2024-08-08 at 1.51.02 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/e/5ed83deffc8f955a19de3b1ab2a0ed72163aea7b.png)

I want to get a response as follows

Gopika Ramesh ---- 2  
Pradini SUrva ----1

Meaning it should find all lookup values and find which repeats top 3 times and give me the response.

How can I get this data from Lookup.

Thank you in advance for help.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 8, 2024, 8:49am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/2 "2024-08-08T08:49:39Z")

</div>

Can I use some Java script to do this?

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 8, 2024, 9:04am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/3 "2024-08-08T09:04:32Z")

</div>

Used this script

function findMostCommonValues(list) {  
let countMap = list.split(‘,’)  
.reduce((acc, curr) =\> ((acc[curr] = (acc[curr] || 0) + 1), acc), {});

let highestCount = Math.max(…Object.values(countMap));  
return Object.keys(countMap).filter(key =\> countMap[key] === highestCount);  
}

let list = p1;  
let mostCommonValues = findMostCommonValues(list);  
return mostCommonValues.toString();

Have configured it like this on my New Column B which has values separated by ,

 ![Screenshot 2024-08-08 at 2.33.09 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/2/d2cd6fdd28ea46d6878022eb0f156bdd4060a845.png)

Can someone let me know if there is any issue in my JS?

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 8, 2024, 9:50am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/4 "2024-08-08T09:50:01Z")

</div>

Let me know if someone has found solution to this issue.

Its a show stopper for one of my feature.

Thank you in advance  
Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 8, 2024, 12:21pm UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/5 "2024-08-08T12:21:33Z")

</div>

So what exact output do you want? Can you give us an example from your input data above?

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 9, 2024, 8:55am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/6 "2024-08-09T08:55:09Z")

</div>

Hi @ThinhDinh

I would want Javascript to Analyse all the Values in the column

and tell me

Gopika Ramesh is selected 2 times  
Pradaini Surva is selected 1 time

Basically show top 3 repeated values.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 9, 2024, 9:34am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/7 "2024-08-09T09:34:13Z")

</div>

If I’m understanding this correctly, then JavaScript is overkill for this. Let me ask a question - do you have a list of unique names in some other table?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 9, 2024, 9:39am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/8 "2024-08-09T09:39:17Z")

</div>

One further question here, why do you seem to have the same list on every line? What’s the ultimate use case of this?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/c/ecbbbc43c074844afe94fc8b5d08b8dfb9b9da93.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/c/6c3e2ae92f8130a2f51216272a1536894b977c0a.jpeg)

If you still want to use JS, here it is:

```auto
function getTopThreeNames(input) {
  const names = input.split(', ');
  
  const nameCounts = {};
  names.forEach(name => {
    nameCounts[name] = (nameCounts[name] || 0) + 1;
  });
  
  const sortedNames = Object.entries(nameCounts)
    .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
  
  const result = [];
  let currentRank = 1;
  let currentCount = sortedNames[0][1];
  
  for (const [name, count] of sortedNames) {
    if (count !== currentCount) {
      currentRank++;
      currentCount = count;
    }
    
    if (currentRank <= 3) {
      result.push(`${name} is selected ${count} time${count !== 1 ? 's' : ''}`);
    } else if (currentRank === 4 && result.length < 3) {
      result.push(`${name} is selected ${count} time${count !== 1 ? 's' : ''}`);
    } else {
      break;
    }
  }
  
  return result.join('\n');
}

return getTopThreeNames(p1)

```

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 9, 2024, 10:02am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/9 "2024-08-09T10:02:56Z")

</div>

Hi @Darren_Murphy ,

Yes I have list of all the Unique names in some table separately.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 9, 2024, 10:04am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/10 "2024-08-09T10:04:12Z")

</div>

> [@ThinhDinh](#):
>
> One further question here, why do you seem to have the same list on every line? What’s the ultimate use case of this?

That’s because its a response from a query that I am getting which I am using.

Will try the script now.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 9, 2024, 10:05am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/11 "2024-08-09T10:05:09Z")

</div>

Okay, so what I would do is as follows:

- Create a multiple relation column in that table that matches the name with the name in your Responses table
- Use a rollup to get a count of responses via the relation
- Use that same table as the source of a Collection
- Order the collection by the count of responses in descending order
- Limit it to 3 rows

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 9, 2024, 10:22am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/12 "2024-08-09T10:22:21Z")

</div>

Hi @Darren_Murphy ,

Thank you for responding.

> [@Darren\_Murphy](#):
>
> - Use that same table as the source of a Collection
> - Order the collection by the count of responses in descending order
> - Limit it to 3 rows

How can I do it? Basically my Input can have Creator 1 2 times , Creator 2 3 times and Creator 3 1 time.

> [@Darren\_Murphy](#):
>
> Use that same table as the source of a Collection

How would this have to be done?

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 9, 2024, 10:27am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/13 "2024-08-09T10:27:01Z")

</div>

> [@Dilip\_Adiga](#):
>
> How can I do it? Basically my Input can have Creator 1 2 times , Creator 2 3 times and Creator 3 1 time.

Use a Split Text column to coerce that into an array, and then match that with the relation.

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 13, 2024, 9:46am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/14 "2024-08-13T09:46:35Z")

</div>

Hi @Darren_Murphy ,

Thank you for replying. Sorry wasn’t working for few days as I was unwell.

> [@Darren\_Murphy](#):
>
> Use a Split Text column to coerce that into an array, and then match that with the relation.

I did this and get the relation, but how can I induce it to give me text like

Creator1 was selected 2 times etc etc in descending order

Specially since names will be different.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 13, 2024, 11:13am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/15 "2024-08-13T11:13:34Z")

</div>

Can you show me a screen shot of what you have so far in the data editor?  
I’m most interested in the table that has the list of unique names.

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 14, 2024, 4:46am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/16 "2024-08-14T04:46:58Z")

</div>

Hi @Darren_Murphy

> [@Darren\_Murphy](#):
>
> Create a multiple relation column in that table that matches the name with the name in your Responses table

I have input my query response to rollup column where I am matching the response of my query which is

![Screenshot 2024-08-14 at 10.10.28 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/f/7f376ee5a1ef50160d6780e61f02f8cf2fef2b5d.png)

From this I am sending it to Lookup column to get creator names

Which is as Below

![Screenshot 2024-08-14 at 10.13.24 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/d/dd8a034a946c5c640f8863326d4bce65359ef565.png)

To this I am applying relation column where it checks the name and compares it with the List where I am storing these creators

![Screenshot 2024-08-14 at 10.14.17 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/7/07776062a9003d0cc4eb25ffcdb0ae3228f35d62.png)

But here instead of 3 I am getting only 2 as one of the names are common

I am getting stuck after this.

I split the text from my lookup column and in my editor I can display it like this

![Screenshot 2024-08-14 at 10.16.26 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/f/5f925abb8268fa6526f0255fa3b2128fb2b52a25.png)

Hope I didnt confuse you.

Thank you for responding.

Regards,  
Dilip

---

<div class="post-metadata">

**Author:** ![MattLB](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mattlb/32/41284_2.png) [@MattLB](https://community.glideapps.com/u/MattLB)\
**Post date:** [August 15, 2024, 1:08am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/17 "2024-08-15T01:08:21Z")

</div>

Dilip - is this accurate?

You have X number of Creators and Y number of Campaigns and Z number of Brands. Brands can have multiple Campaigns. Creators work on multiple Campaigns across multiple Brands. Campaigns are associated with ONE Brand but potentially Multiple Creators.

You want to list the top 3 Creators and the # of Campaigns they worked on across all Brands- correct?

---

<div class="post-metadata">

**Author:** ![Dilip\_Adiga](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/dilip_adiga/32/60330_2.png) [@Dilip\_Adiga](https://community.glideapps.com/u/Dilip_Adiga)\
**Post date:** [August 16, 2024, 11:43am UTC](https://community.glideapps.com/t/need-help-in-extracting-similar-names-in-lookup-response-and-also-get-the-count-of-times-repeated/75511/18 "2024-08-16T11:43:28Z")

</div>

Hi @MattLB ,

Thank you for responding.

Basically I have X number of Creators, Who have worked on Y number of campaigns.

And Z number of agency is associated with these campaigns.

Yes one brand is associated with multiple creators.

I want to list the Top 3 creators who worked with selected Agency.

Regards,  
Dilip
