Download tags with counts?

Hi! Newbie to Obsidian, only 2 weeks in, already hooked!

I’m wondering if there’s a way to download a csv or json of all tags with their counts. Basically, the tag sidebar, but downloaded.

What I’m trying to do

I have imported notes from a variety of sources and am left w/ a lot of tags that only refer to one file. I’d like to remove all of these since they no longer make sense within the context of a “second brain”.

If I could download them, I could set up an R script to programmatically remove the # from tags w/ a count less than 2 or 3 or whatever.

Things I have tried

  • copypasting from the sidebar, no joy
  • Downloading plugins like Tag Wrangler, but couldn’t find any that have the functionality I want
  • Could a dataview work?

Hello.

Would this work for you?

```dataview
TABLE WITHOUT ID (tag + " – " + length(rows.file.link) + "") AS Tags
FROM ""
WHERE file.tags 
FLATTEN file.tags AS tag 
GROUP BY tag
SORT length(rows.file.link) DESC
```

Reference: Creating a tag index table with Dataview? - #11 by mnvwvnm

1 Like

I’d rather use file.etags in such a query, as your query would split and count every part of a nested tag.

Look at the output of this query:

```dataview 
TABLE file.tags, file.etags
WHERE contains(string(file.etags), "/")
LIMIT 5
```

Notice how the first variants splits all the nested tags.


So here is a similar query showing the tags with their count:

```dataview
LIST count
FLATTEN file.etags as tag
GROUP BY tag
FLATTEN length(rows) AS count
WHERE count > 10
```

Here you could change which count of tags you want to see in the last line.

Also note that if you truly want a static count of tags, you could consider calling this query from within a Templater template, and insert the result into a note somewhere.

2 Likes

Very nice. Don’t use nested tags, but useful to know. Prefer a table, so for me:

```dataview
// table of tags and quantity //
TABLE Number
FLATTEN file.etags as Tags
GROUP BY Tags
FLATTEN length(rows) AS Number
SORT length(rows.file.link) DESC
```
1 Like

Thanks both! Those solutions both work! I guess from there it’s just a matter of copying into a txt and converting to csv? Or is there a good way to output to csv from a dataview?

Both of your answers look great, Ill accept holroy’s because of the nested tags.

Thanks!

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