Dataview: how to show notes that have tags in common with the current note?

Hi all!

is there a way (using Dataview) to display all notes that have at least one tag in common with the current note?

I tried this, but it works only if all tags are identical.

table ColumnOne, ColumnTwo
where contains(file.folder, this.file.folder) and file.tags = this.file.tags

Hi,

There is a difference between “exact” correspondence (=) and “included” (contains).

In your case, what is “exact” is the folder. So, for folder filter you can use file.folder = this.file.folder.

About tags, file.tags = this.file.tags means, as you confirmed, identical, i.e., all tags need to be identical.

To your intent, you need to filter tags in a more complex way. In a direct logic we can think to use WHERE contains(file.tags, this.file.tags), i.e., “all notes that include the tags of this note”. But this.file.tags is an array and you got as result all your notes. For solve this we can use the function any() (it works, don’t ask me what’s the logic :slight_smile: ).

In conclusion:

```dataview
TABLE ColumnOne, ColumnTwo
WHERE file.folder = this.file.folder AND any(contains(file.tags, this.file.tags))
```
3 Likes

Thank you! this works as intended. :slight_smile:

Also, if a user use nested tags, probably using “etags” returns better results

TABLE ColumnOne, ColumnTwo
WHERE file.folder = this.file.folder AND any(contains(file.etags, this.file.etags))
2 Likes

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