Count how many times a certain tag is repeated on a page

I hope to get a table like this as a result:

file | count
file 1 | 3
file 2 | 5

count: Number of times a certain tag is repeated in the same note

The specific tag I want to count is one of my choosing, like #example or any other I choose

Please try searching the forums before asking, as we recently covered getting tags out of the metadata cache in this post.

An adapted version of that script for your case is as follows:

const tagToCheck = "#Agenda/Fred"

const tFile = app.vault.getAbstractFileByPath(dv.current().file.path)
const tagCount = dv.array(app.metadataCache.getFileCache(tFile).tags)
  .where(t => t.tag == tagToCheck ).length
dv.span("There are " + tagCount + " reference(s) to " + tagToCheck) 

Change the tagToCheck to match your case, and the text of the last line to match your liking.

1 Like

I really appreciate that you took the time to help me, I will try to learn how to use dataview in a more in-depth way

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