Remove duplicates from a dropdown connected to a dataset filtered by a second dataset


I need help with a dropdown connected to a dataset, I don’t want the duplicates to show. I know ways to hide the duplicates (i.e. this code ) but I have a problem… My dataset is filtered by a second dataset.
To explain better, I have a product page which is connected to a Product dataset. On each product page I want a filtering function where customers can use dropdowns to filter options like “Product size” and then the results will show the exact article number based on their choices (I use a repeater for this). I want to do this because every product is available in a lot of different sizes, colours etc. I only want to show the results relevant to the product they have already chosen, the product page they are at. When I connect a dropdown to a column in my second dataset, it only shows the relevant options based on the first dataset, exactly as I want. BUT duplicates show. If I use the code to remove duplicates as the link above, it will show all options in that column in the collection. So if I for example have one product in my first collection named Sara and one named Anna, and Sara is available in sizes 20cm and 30cm, and Anna is available in 20cm and 50cm. If I am on Sara’s product page, I only want the options 20cm and 30cm to show in the dropdown.
Is there any way to do this? Maybe something to add to the code from the link, to hide options with no hits?

I really need help, thanks in advance!

You might want to try using the distinct() query function to eliminate duplicates. See Example: Remove duplicates from connected dropdown options using distinct() query to see how it’s used.

Thank you for your fast response! Unfortunately it does the same thing for me, I still get all the options in the dropdown, I only want to show options with hits. Do you have any other suggestions?

@wilmabergdahl Did you try running the example itself to understand how it works? How did you apply it to your own code? Show us how you did it?

@yisrael-wix There’s probably a better way to do it, but I simply changed “Continent” to my collection ID, “iContinent” to my dropdown ID, “dataset1” to my dataset ID. I think the problem is how I changed “iTitle” (search bar) and “articleTitle”, I don’t fully understand how to change that to depend on my first dataset instead of the search bar. The way I have set it up is that I have a column called Title in both datasets which is the name of the product. The filtering results are connected to only show results with the same title as the title of the product page you’re visiting (and this works fine). So how do I make this code to show only the available options?
I’m very thankful for your help.

@yisrael-wix Any suggestions?