I have notes per person and notes per company. Tagged with #Person and #Company respectively in the YAML frontmatter.
Now I want to use dataview in the Company notes on all the people that work for that company. The way I linked these is by using a property called “Company” in the person notes where I can link one or multiple company notes.
The dataview query in the company note to gather all people should thus only include person notes that have the company linked through the frontmatter properties. I want to exclude person notes where the company is only mentioned in the body of the note (not the frontmatter).
Things I have tried
I started out with the very simple:
LIST
FROM #Person and [[]]
which of course included all notes that had a link.
Then I tried this:
LIST
WHERE contains(tags, "#Person") and contains(Company, this.file.link)
SORT file.name ASC
But this now seems to not show any person notes and I have no idea what I’m doing wrong.
Can you post a couple examples of what your frontmatter looks like? Your WHERE clause looks reasonable, but I wonder if it’s a data issue. This clause expects each Company field to contain a list of companies, and won’t work if the company field has a single item.
For example, this frontmatter entry looks like it would work with your query:
The issue is likely how the Company field is structured. contains() only works if it’s a list. If some notes use a single link and others use a list, your query won’t catch both.
This should handle both:
LIST
FROM #Person
WHERE Company = this.file.link OR contains(Company, this.file.link)
SORT file.name ASC
Covers both [[]] and - [[]] without needing consistent formatting.
Didn’t test this before posting, but it should point you in a direction. Whether it’s the right direction, that’s still up in the air
@Craig@camadkins thanks for explaining that! It does indeed seems that this was the issue since sometimes a person is active at multiple companies the “Company” property is of a list type but sometimes with one note linked.