I have a number of notes with different values in the same property (propertyA). Trying to list all notes that have either value1 or value2 in propertyA. I want to include notes that have one of either values.
Things I have tried
I’ve tried searching for any number of ways of phrasing this problem but can’t seem to find the solution. Have tried looking through dataview commands many times but can’t seem to find the way to give the command value1 OR value2.
Tried these commands:
list where propertyA=“value1” OR “value2”
list where propertyA=(“value1” OR “value2”)
list where contains(propertyA,“value1” OR “value2”)
list where contains(propertyA,(“value1” OR “value2”))
The trick is to use contains() or to duplicate the checks. So either of the following should meet your request, as long as propertyA holds a single value.
LIST WHERE propertyA = "value1" OR propertyA = "value2
LIST WHERE contains(list("value1", "value2"), propertyA)
The latter variant is very useful if you want to compare against more than a few variants.
LIST WHERE propertyA = "value1" OR propertyA = "value2
This seems to only work when propertyA is a text. Doesn’t seem to work here and I think it might be because propertyA is a list.
LIST WHERE contains(list("value1", "value2"), propertyA)
I might be doing something wrong, but this weirdly seems to list a lot of notes that have some kind of value in propertyA, but not the particular ones specified, ie. including value3, value4 etc.
Then you need to show some examples of what propertyA might contain, and describe whether it’s always a list or just every now and then. We can’t give precise answers when we don’t know the details of your setup.
If it helps for context, I’m a gardener who sows seed. Some seed need treatment, e.g. stratification (some cooling time). The concrete thing I’m trying to do is list all seed with treatment needs (propertyA) that are either “short stratification” (value1) or “no stratification” (value2).
In some notes (plant notes) the property ‘seed treatment’ contains one value and thus by default becomes a text, I think. In others, it contains several values and becomes a list, I think.
The code above only works if propertyA is a list, right? Is there are way to always make propertyA a list?
Doing flat(list( propertyA )) will make it into a list, whether it was a list or not from before
Since we want to check against multiple values, we need to change gears, and map the comparison, and finally check if any of them matched.
So how does this look in the query? Something like this:
```dataview
LIST WHERE any(map( flat(list(propertyA)),
(m) => econtains(list("no stratification", "short stratification"), m)))
```
To reiterate this check if any of the mapped items are true. The mapping maps the enforced list of propertyA, and for each of them it checks if that particular property, m, is found in the list of “no stratification” and “short stratification”. Note that I’ve switched to econtains() to match against the entire text, since stratification would match against either if not we do an exact match.
If you happen to write either of your properties with mixed case you need to change the last part, , m))), to , lower(m)))). In fact, you could just do that immediately, to save yourself some pain in the future if you introduced mixed casing somewhere…
Hope this helps, and that I understood your case well enough, and explained the new query well enough.
It should switch to econtains() as the OP has established that some of his values can be part of another value. Other than that, you could use that variant which would be a lot simpler. I sometimes get caught up in a chain of thoughts, and fail to recognise that easier solution. Good catch, @Anwen .
Thank you both. In my own language (Danish) it was possible to use @Anwen 's simpler solution. But thank you holroy for mentioning the possibility of econtains - how do you learn all these commands? Dataview is like an entirely independent coding language I have no idea where to look for all these queries.