# Limit number of item for charts

**URL:** <https://community.glideapps.com/t/limit-number-of-item-for-charts/18811>\
**Category:** Ask for Help\
**Created:** [November 23, 2020, 1:07pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811 "2020-11-23T13:07:02Z")\
**Posts on this page:** 6\
**Page:** 2

<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:** [November 24, 2020, 3:57pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/21 "2020-11-24T15:57:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/7/97acb698419546eaf1c30dd80e8dc86454aaebb6.png)

Here’s the solution.

I add this custom function in the Tools \> Script Editor, then use it as a custom function.

The closest date from now will be ranked 1st, then 2nd etc., based on each activity.

```
function customrank(arr) {
  arr = arr.filter(function(r) {
return r[0] != "";
  });
  return arr.map(function(r1) {
return arr.reduce(function(rank, r2) {
  return rank += (r2[0] == r1[0] && r2[1] > r1[1]);
}, 1);
  });
}

```

> **[Thinh Dinh's lab V2.0](https://docs.google.com/spreadsheets/d/1JzBrp4R1zK9CMfmTzWWcPPep9-ZCl3OXxgWu27NWCy8/edit#gid=1032605303)**
>
> Profile
> 
> ID,Email,Name,Image,🔒Row ID
> 1,ariesarsenal@gmail.com,Thịnh Đinh,\<a...

---

<div class="post-metadata">

**Author:** ![F\_rank](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/f_rank/32/30511_2.png) [@F\_rank](https://community.glideapps.com/u/F_rank)\
**Post date:** [November 24, 2020, 5:29pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/22 "2020-11-24T17:29:52Z")

</div>

Awesome it is working!

 ![Capture d’écran, le 2020-11-24 à 12.37.47](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/1/f11b35c6643a3ac1b561d0e80eae7d26ff9c6c70.png)

 ![Capture d’écran, le 2020-11-24 à 12.39.41](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/d/8d03be09bd222c5173f0a918ce387bf7c2c99a51.png)

First time I use script editors tho… if someone copy the app & google sheet, will they have the custom code too?

---

<div class="post-metadata">

**Author:** ![F\_rank](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/f_rank/32/30511_2.png) [@F\_rank](https://community.glideapps.com/u/F_rank)\
**Post date:** [November 24, 2020, 8:33pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/23 "2020-11-24T20:33:14Z")

</div>

> [@ThinhDinh](#):
>
> You do need to rank by each user, is that correct?

It’s me again @ThinhDinh. Thanks again for the perfect solution.

If I want the rank to be user specific, what would be the custom function?

---

<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:** [November 24, 2020, 10:12pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/24 "2020-11-24T22:12:18Z")

</div>

The scripts won’t be copied over when someone else is duplicating your app.

If you want it to be user specfic then capture the user email in each row, then join the email and the activity in a helper column.

Something like.

```
={"Joined info";ARRAYFORMULA(IF(A2:A<>"",A2:A&""&B2:B,"")}

```

Then use that helper column and the date for the rank formula.

---

<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:** [November 24, 2020, 11:54pm UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/25 "2020-11-24T23:54:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/3/63b7bdead8ee435c6208260e8d5a580f8b4f1d54.png)

Here @F_rank, I demonstrated what I mean in the previous comment, then used a query to order the table so you know the rank is working correctly.

> **[Thinh Dinh's lab V2.0](https://docs.google.com/spreadsheets/d/1JzBrp4R1zK9CMfmTzWWcPPep9-ZCl3OXxgWu27NWCy8/edit#gid=1032605303)**
>
> Profile
> 
> ID,Email,Name,Image,🔒Row ID
> 1,ariesarsenal@gmail.com,Thịnh Đinh,\<a...

---

<div class="post-metadata">

**Author:** ![F\_rank](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/f_rank/32/30511_2.png) [@F\_rank](https://community.glideapps.com/u/F_rank)\
**Post date:** [November 25, 2020, 12:52am UTC](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811/26 "2020-11-25T00:52:54Z")

</div>

@ThinhDinh you are da man. Seriously, it’s like magic. It’s a serious asset to know custom functions!

I like to think that one day Glide will be able to do all that, but until then we have you 😃 🔥

[Previous page](https://community.glideapps.com/t/limit-number-of-item-for-charts/18811.md?page=1)
