List common tags except THIS but don't exclude them if they have THIS

I’m trying to use dataview on notes to show other notes that share common tags.
I want to exclude some common tags from the criteria.
However, I don’t want to exclude the note note from showing up because they have said tags.

Use case:

Note A has the tags:

  • blog
  • goals
  • time

Note B has the tags:

  • blog
  • goals
  • management

Note C has the tags:

  • blog
  • cooking
  • chicken

Note D has the tags:

  • journal
  • reading

Dataview’s role

If I’m in Note A, I want dataview to show Note B having common tags, but exclude Note C.
What I’m trying to accomplish is to not include blog as a tag in the criteria in-common criteria without excluding it.

I’ll provide the following query:

Dataview query

	link(, title) as Note, common, unique
	array(filter(file.etags, (f) => econtains(this.file.etags, f))) as common FLATTEN
	array(filter(file.etags, (f) => !econtains(this.file.etags, f))) as unique WHERE
	length(common) > 0 AND !contains(file.path,this.file.path)
SORT updated DESC

This problem, as it stands, can be solved by changing length(common) > 1, but that won’t work out well when adding nested tags (e.g. blog/faq, blog/keyword) into the mix.

Thank you

I appreciate you taking the time reading or helping me out.
I believe there’s a simple solution here that I’m just not getting…

Do you just want to ignore the tag #blog or is this just an example? In other words: are you looking for a general “fits-all-possible-cases-query” that doesn’t have to be adapted no matter what tag you want to exclude? Or are you satisfied with a query that meets your criteria and just ignores (but not exludes) “#blog”?

I’ll be satisfied with either.
A simpler solution or a less computing resource intensive option would be best.

Try if this gives you your desired results:

TABLE WITHOUT ID Tags, map(rows, (r) => "* " + link(, r.title)) AS Notes
FLATTEN file.tags as Tags
WHERE (econtains(this.file.etags,Tags)) AND !contains(Tags,"#blog")

In different queries, replace “#blog” with the tag you want to ignore.

1 Like

This works! Thanks. I added a rule to not list the exact note I was looking at, and it serves my needs well.

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