Help with dataview query with multiple list values

I have a series of notes that I take, which relate to my interest in specific companies. So I have an “Organizations” property (property type: list) that allows me to list multiple companies that may have been featured in the note. Each note may have multiple organizations listen under the “Organizations” property.

Each of these companies has its own note also. The title of these notes is the name of the company itself, but I also add a property (property type: text) to these ‘company’ pages called “Company”, which is the name of the company itself - same as the title. On this page I wish to create a dataview table that lists ‘Notes related to this company’. This is my code:

table Created
from "Notes"
where Organizations = this.Company
sort Created desc

The issue I face is that this code works fine when there is only a single entry in the “Organizations” property of the note. However when there are multiple entries under “Organizations”, the code starts listing every note in the folder.

Would appreciate some help.

When comparing against a list you can’t use the equal sign as that compares a single value towards a single value, which you’ve experienced. So a better option for your where clause is to use:

WHERE contains(Organizations, this.Company)

In most cases that should suffice. I sometimes tend to do WHERE contains(flat(list(Organizations)), this.Company), as this would ensure that the first input to contains() is always considered a list no matter what you’ve defined is as. The list() ensures the parameter is considered in a list context, and the flat() removes any extra multi-level issues if it was a list from the start on.

Thank you! This worked perfectly for me.

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