If your “tags” are in frontmatter I know how to solve this. But with implicit field file.tags I found some limitations in using data commands “GROUP BY” and “FLATTEN” in simple dataview queries (maybe these limitations have a solution in dataviewjs, but I’m not able to do that).
Just some points:
your “file.name” is a list of files (if tag is used in more than one file) - a list equal to the count of files with that tag
if you want not a string but a link, you need to use “file.link”
Considering what I said before, I think I have found a way to do that with file.tags.
But first I need to clarify the points about “Folder” and “File Name”
For each tag you want:
a) The total (number) of the files using that tag?
b) The list of files? (It’s a list, not an ‘single’ object - a list with the files counted in file.tags)
c) The list of folders? (It’s a list, because if you have a list of files in b), then you have a list of folders - even if the files are all in the same folder)
About the table:
d) Do you want the table sorted by the total in a)?
Maybe I was not very clear about the issue of files and folders: was on how these elements appear in the desired table - lists of files and lists of folders for each tag.
But the best way to clarify this is advancing with hypotheses for your table.
Table with “folders” and “files” presented as lists:
```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, (rows.file.folder) AS Folder, (rows.file.link) AS Files
FROM ""
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT length(rows.file.link) DESC
```
Table with “folders” and “files” presented as joined lists:
```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, join(rows.file.folder) AS Folder, join(rows.file.link, ", ") AS Files
FROM ""
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT length(rows.file.link) DESC
```
Is there a way to sort the items inside the “file column” each row in ascending order ?
I added sort which does not work.
SORT Files ASC
like this
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, (rows.file.link) AS Files
SORT Files ASC
FROM "" WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag SORT length(rows.file.link) DESC
```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, sort(rows.file.link) AS Files
FROM ""
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT length(rows.file.link) DESC
```
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, sort(rows.file.link) AS Files
FROM ""
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT length(rows.file.link) DESC
This does the job but…
sort(rows.file.link) AS Files
this sorts all files in alphabetic order inside a Folder, but not across all folders.
Well, I never used some similar to this query. But I accepted the challenge as a way to learn more about the potential of Dataview.
Because many of the hypotheses are found by the “trial-error” method (not any special knowledge in code), in some cases things seems to work in my limited test vault. But, applied to a more complex vault, the issues becomes more specific.
In this particular issue, I deduce the problem is in file.link. What is a link? Is a file path… rendered with the file name. So, I deduce the function sort in file.link is applied to the file path (something like Folder1/Foucault.md, Folder2/Adorno.md > all files in Folder1 are sorted before files in Folder2).
How to overcome this limitation?
The immediate answer is use file.name instead of file.link.
sort(rows.file.name) AS Files
But (now is my turn), you want “links”, not a simple list of names.
To do that, let’s try the function link presented in the plugin documentation:
link(sort(rows.file.name)) AS Files
In conclusion, try this query and tell me if my empiric deduction works:
```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, link(sort(rows.file.name)) AS Files
FROM ""
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT length(rows.file.link) DESC
```
```