# To "distinct" or not "distinct"

**URL:** <https://community.weweb.io/t/to-distinct-or-not-distinct/19945>\
**Category:** Ask us anything\
**Created:** [September 10, 2025, 5:57pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945 "2025-09-10T17:57:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpaim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mpaim/32/14016_2.png) [@mpaim](https://community.weweb.io/u/mpaim)\
**Post date:** [September 10, 2025, 5:57pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/1 "2025-09-10T17:57:43Z")

</div>

Hi there,  
I would like kindly ask for a hand in a issue that is stucking me.

On my Select, **using “rollup with distinct” and “lookup”,** the result is not getting the data from the fiels as expected, in my example “1º Ano”. it only shows the “id”. **So, distinct works, but lookup does not list the expected result.**

Trying a different approch, **using only a Collections or “filterByKey”, the “distinct” not work, but the the lookup works and format is correct, but there is duplicates on the list.**

 ![selectIssue](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/7/76b9bfa53d1eff9fecd8553b51e0e34d9df4ed5d.png)

I’ve tried a lot of combinations between formulas and using others too, nothing works for me until now.

I really appreaciate any help on this.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Dan\_OOT](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dan_oot/32/14475_2.png) [@Dan\_OOT](https://community.weweb.io/u/Dan_OOT)\
**Post date:** [September 10, 2025, 9:01pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/2 "2025-09-10T21:01:12Z")

</div>

Might just be missing something because I’m still waiting for the coffee to set in this morning… but I see in both your uses of lookup, you don’t use the whole function. Is this intentional? Does using it fully still not get you the result you’re after?

The full function just for reference: “lookup  
Return the first object in array in which key is equal to value

Default value for key is ‘id’

lookup(value, array, [key])”

So it looks something like this (ignore the if statement it’s wrapped in, I just screenshot one out of my own code):

![Screenshot 2025-09-11 065607](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/4/4208d1beaeb6ec5e258904a12daf8f2b311a6e74.png)

So “chair\_name” is a field within my .data that I’m referencing the value of a select against and pulling up all instances where the chair\_name matches, then getting the .is\_upholstered as the result I want to display the select this lookup is in.

---

<div class="post-metadata">

**Author:** ![mpaim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mpaim/32/14016_2.png) [@mpaim](https://community.weweb.io/u/mpaim)\
**Post date:** [September 11, 2025, 12:05am UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/3 "2025-09-11T00:05:55Z")

</div>

Hi Dan,

Thanks for your reply, I did some tests with the [key] inside the “lookup” for the many formulas I am using on the Options and there is no change on the results.

If I could find a way to avoid duplicates on the lists of objects for the grade\_id, it would be fixed quickly.

If you have any other suggestions, please let me know. I will keep trying. But this issue is really weird ; )  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Dan\_OOT](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dan_oot/32/14475_2.png) [@Dan\_OOT](https://community.weweb.io/u/Dan_OOT)\
**Post date:** [September 11, 2025, 12:37am UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/4 "2025-09-11T00:37:33Z")

</div>

So you’re pulling this information from an array of objects by the look of it, and that array contains multiple results that has duplicate grade\_ids and grade\_names in it. Even if you do find a way to get no duplicated results, how do you know you’re referencing the correct object in the array? What’s the purpose of the array and the select?

You can do multi-layer lookups/filters. Personally I would set your option to reference the .data array, and then use the Filter option (listed below the Formula field) to filter down until I go the results I wanted. Like here, where i have certain information intentionally duplicated in the database so I can use multiple select fields to gradually narrow down what option I want until I get just three unique objects that are relevant.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e05914d15ab6c5dd0183892394dab24e1e9d4b54.png)

Dunno if that’s helpful or not. It’s hard to say for sure without knowing what you’re trying to achieve with the array and why there are duplicate results in there at all.

---

<div class="post-metadata">

**Author:** ![mpaim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mpaim/32/14016_2.png) [@mpaim](https://community.weweb.io/u/mpaim)\
**Post date:** [September 11, 2025, 3:03pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/5 "2025-09-11T15:03:24Z")

</div>

Hi Dan,  
Thanks for the suggestion. I have a table where grade\_id is a column with FK to another table “grades”.  
The main objective is to assign ids from Classes to Grade on a table with FKs.  
I am exploring your suggestion, but until now I couldn’t solve the issues: Or I have the format expected like 1º Ano duplicated or I have the non-duplicated without the format like “1”.  
What is weird is that the “Current Value: 1º Ano” and it do not display this on the Select.  
I also have created a function and a trigger to bring to a column grade\_name on Supabase and even though, the select is not showing the expected format. I will keep trying with your suggestion…If you have any other insight, please let me know.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![mpaim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mpaim/32/14016_2.png) [@mpaim](https://community.weweb.io/u/mpaim)\
**Post date:** [September 11, 2025, 5:41pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/6 "2025-09-11T17:41:52Z")

</div>

Hi there,  
After spending a lot of time trying to fix this, the most elegant solution (kind of ; )) was to create a Supabase View.  
A SQL like this works like a charm and will save a lot of time if you are stuck in a similar situation.

create or replace view school\_grades\_unique as  
select distinct  
school\_id,  
grade\_id,  
grade\_name  
from  
school\_classes;

Have a great day!

---

<div class="post-metadata">

**Author:** ![Dan\_OOT](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dan_oot/32/14475_2.png) [@Dan\_OOT](https://community.weweb.io/u/Dan_OOT)\
**Post date:** [September 11, 2025, 8:30pm UTC](https://community.weweb.io/t/to-distinct-or-not-distinct/19945/7 "2025-09-11T20:30:47Z")

</div>

Glad you found a solution that works for you!
