# How to create a list of numbers (in CSV format) based on a set of criteria

**URL:** <https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562>\
**Category:** Ask for Help\
**Created:** [July 31, 2023, 9:27pm UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562 "2023-07-31T21:27:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [July 31, 2023, 9:27pm UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/1 "2023-07-31T21:27:41Z")

</div>

Scenario: Each user on an app can buy event tickets that are numbered 1 to 1000 BUT they cannot buy a ticket that is within 10 places of any tickets they’ve already bought.  
So if the first ticket they bought is ticket number 30 then they cannot buy any tickets between 20 and 40 (ie. they cannot buy tickets with the number 20,21,22,23,24,25…38,39,40)

NB: if they buy ticket 30, 45, 82 then the list of ticket numbers they cannot buy next are (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,54,55 as well as 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92)  
if the result could be listed as comma separated values then i could use it to hide buttons that they aren’t allowed to buy.  
Any ideas how this can be done. Is it possible with Query column?

---

<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 1, 2023, 2:26am UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/2 "2023-08-01T02:26:40Z")

</div>

I think you can use JavaScript for this.

```auto
function getInvalidTickets(purchasedTickets) {

  if (typeof purchasedTickets === 'number') {
    purchasedTickets = [purchasedTickets];
  } else {
    purchasedTickets = purchasedTickets.split(',').map(Number);
  }

  const ranges = purchasedTickets.map(number => {
    const min = Math.max(number - 10, 1);
    const max = Math.min(number + 10, 1000);
    return {min, max}; 
  });

  const invalidTickets = [];

  ranges.forEach(range => {
    for (let i = range.min; i <= range.max; i++) {
      if (purchasedTickets.some(num => Math.abs(num - i) <= 10)) {
        invalidTickets.push(i);
      }
    }
  });

  return invalidTickets.join(',');
}

return getInvalidTickets(p1)

```

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

---

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [August 1, 2023, 6:44am UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/3 "2023-08-01T06:44:24Z")

</div>

Wow, thanks for that, it looks perfect. I’m going to test it out right now. Thanks a million!

---

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [August 1, 2023, 8:14am UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/4 "2023-08-01T08:14:17Z")

</div>

Thanks @ThinhDinh it works perfectly👌

---

<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 2, 2023, 12:38am UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/5 "2023-08-02T00:38:23Z")

</div>

Great to hear!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [August 9, 2023, 12:38am UTC](https://community.glideapps.com/t/how-to-create-a-list-of-numbers-in-csv-format-based-on-a-set-of-criteria/64562/6 "2023-08-09T00:38:41Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
