Dataview: Create a table that automatically registers nested tags, then lists which files have them

Hey. I’m trying to create a table using the Dataview plugin that creates 2 columns: One automatically lists every nested tag under “#mc”, and the other lists every file using that particular tag.

For example:
| Nested Tag | Files |
| — | — |
| #mc/john | [[Chapter 1]] [[Chapter 2]] [[Chapter 5]] |
| #mc/richard | [[Chapter 2]] [[Chapter 3 ]] [[Chapter 6]] |

Essentially, it would automatically know when I create a new nested tag under “#mc” and then list it as it’s own row in the table, alongside every file that contains it.

I did a lot of googling and kind of frankensteined a solution that almost works. It’s able to list every file that specifically has the exact text of “#mc”, and not any nested tags, unless I manually write those down.

The code:
TABLE WITHOUT ID (tag + "(" + length(rows) + ")") AS "Tag", link(sort(rows.file.name)) AS "Files"
FLATTEN file.etags AS tag
WHERE contains(file.etags, "#mc")
WHERE tag = "#mc"
GROUP BY tag
SORT length(rows) DESC

I need some kind of “wildcard’ search I could append to “#mc” so it automatically assumes any nested tag is part of the query.

I’m not particularly skilled in Dataview, and unfortunately a lot of it is just a bit out of my grasp of intelligence, but I’d really like to try and get things tidy and organized in my vault using it, so any help is appreciated, thanks. I can clarify anything that needs it.

Figured it out:

The solution is this:
```dataview
TABLE WITHOUT ID (tag + " (" + length(rows) + “)”) AS “Tag”, link(sort(rows.file.name)) AS “Files”
FLATTEN file.etags AS tag
WHERE startswith(tag, “#TAGHERE/”)
GROUP BY tag
SORT length(rows) DESC
```

This makes sure every new nested tag is counted, and lists every file that has said tag.

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