Dataview list of pages that contains value in a list, and only that value

What I’m trying to do

I have a collection of fruit varieties with each their own page. Each page has a property for distributors I can acquire them from. Many varieties I can get from several sources, so the property ‘distributor’ is a list with several possible values. I want to list the varieties that I can only get from a specific distributor, ie. a list of all pages that contain the property ‘distributor’ and only has one specific value (that particular distributor) and no other values.

Things I have tried

I tried searching the forum for ‘only one value list dataview’. I’ve before made queries where I include one distributorA, and manually exclude all the other distributors (B, C, D) like this

WHERE contains(distributor,“distributorA”)
WHERE !contains(distributor,“distributorB”)
WHERE !contains(distributor,“distributorC”)
WHERE !contains(distributor,“distributorD”)

The problem is I might have a new distributorE coming along and then I need to manually edit all those lists.

Is there a way to say, for lists,
WHERE contains-only(distributor,“distributorA”) ?

I think the safest variant is a little ugly, but since the distributor could be a single item or multiple values I’d use the following:

WHERE length( flat(list(distributor)) ) = 1

This ensures that the distributor field is always considered a list (and reduced to one level in case it was a list already).

1 Like

Awesome, that worked like magic. You’re the dataview wizard, @holroy - thanks!

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