First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.
What I’m trying to do
I try to use the GROUP BY functon of the dataview plugin, but somehow the result looks broken.
Things I have tried
Checked the Syntax based on the documentation. Pretty sure I just missed something. Same behavior with TABLE.
I expected to see something like this:
Typ/Author
** Morgen, Richard
Typ/Buch
** Das Unsterblichkeitsprogramm (Buch)
** Skorpion (Buch)
When you group by a field, the field becomes the main field instead of the notes links. So, if you make a list without fields and you group, the notes links no longer appear, you have to add the links in the fields to display like this:
LIST rows.file.link
WHERE contains(Genre,[[Scienence Fiction)]) AND file.name != this.file.name
GROUP BY tags
SORT Datum DESC
LIMIT
There are a few things happening in your script which might not be wanted. First of all when you do any GROUP BY statement it’ll change the key to your group by expression. For a list the key defaults to the file name, so when changing it, you’ll now list the “tags”.
Secondly, whenever you do GROUP BY all files matching that key, will be grouped into the rows object. So if you had file.link, it’ll now become a row in rows, like in rows.file.link.
Thirdly, tags is a collection of all the tags from any given file in your query. So if you have one file tagged #a #b, and then another tagged just #a, and a third tagged #b this will become three distinct groups of tags, and I reckon you’d only want to two, one for #a and one for #b.
So to counter these issue try the following query:
```dataview
LIST rows.file.link
WHERE contains(Genre, [[Scienence Fiction]])
AND file.name != this.file.name
FLATTEN file.etags as tag
SORT Datum DESC
GROUP BY tag
LIMIT 100
```
Here I’m flattening file.etags into each tag, which is the best approach for getting the single unique tags of any given files, on the file list limited by your WHERE clause. I’m also sorting before the grouping, but this can be adjusted.