Showing notes with similar tags showing multiple times

Hi.
I am trying to have notes that share tags displayed in notes.
I use the following to accomplish that, but there is one problem I would like to solve.

TABLE WITHOUT ID
	row.file.link as Note, tag as Tags
FLATTEN file.tags as Tag
WHERE
	!contains(file.path,this.file.path) AND econtains(this.file.tags,Tag)

This would currently display the same notes multiple times if they share multiple tags.
Is there a way to let it not show the same similar notes multiple times?
I tried GROUP BY row.file.link, but that made the row.file.links appear invalid.

I appreciate the help.
Thanks

Table rows.file.link as "Notes"
FLATTEN file.etags as "Tag"
GROUP BY Tag as "Tags"

this should give you what you want.

You’ve got to choose what you want to display when doing stuff like this. If the rows in your table is one row for each tag, then the files having multiple matching tags will be duplicated. If the rows are one for each file, then you’ll be duplicating the list of the matching tags.

So which part do you want to duplicate in the row, and what do you want to focus on in each row of your table?

I want to show similar notes to the current note by tags in common. Ideally each row would have the link to an individual note that has at least one tag in common.
I apologise for not being thorough.

so my solution is not what you want?

No need to apologize, it’s just a rather specific request which needed a little clarification. So try the following query:

```dataview
TABLE  WITHOUT ID file.link as Note, common, unique
FLATTEN 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
```

The trick to this query is that both the origin file and the candidates may have multiple tags, so you’ll need to do a double loop. In the query this is accomplished through doing a filter() for one loop, and the econtains() for the other loop. To preserve the output from the filter as a list, the expression is surrounded by an array() function.

The second FLATTEN producing the unique is not needed, it’s just for debug purposes, and can be removed if you want to.

The WHERE clause can be simplified into WHERE common or WHERE length(common), but doing WHERE length(common) > 0 has a higher readability and showcases what’s actually happening on that line.

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks or queries) is properly shown.

1 Like

This is pretty much what I am looking for. Thank you!

Not precisely but I am using this as well now.
This cleared up how FLATTEN and GROUP BY works.
Thanks.

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