In dataview, how to get number of linked mentions, not only the number linked files

What I’m trying to do

In dataview, is it possible to get a summary how often a note got mentioned? Pretty much like in obsidians sidebar, but in dataview.

2024-02-06 12_17_25-Clipboard

Things I have tried

i tried this querry:

	type as Type, length(file.inlinks) as Total
FROM #mytag
WHERE contains(file.folder, this.file.folder)

But what it delivers is not the number of mentions, but the number of files that link to it. So if I got 200 links to my note from a single file, it all counts as “1” in that querry.

Using an ordinary DQL query it’s not possible, but if you switch to dataviewjs you could start looking into the metadata for each file, and build your own result. Here is a script looking at files in the current folder, and counting inlinks for each file:

// console.log("\n\n New run")
// console.log(await app.vault.getMarkdownFiles().slice(0, 10))

const result = await dv.pages(`"${ dv.current().file.folder }"`)
 .map(p => {
   // console.log("Current file: ", p.file.path, p.file.inlinks?.length)
   let totalInlinks = 0
   const currentFile = p.file.path
   for (const inlink of p.file.inlinks) {
     // console.log("  ", inlink.path)
     const tFile = app.metadataCache.getFirstLinkpathDest(inlink.path, "")
     const fileCache = app.metadataCache.getFileCache(tFile)
     // console.log("fc: ", fileCache)
     if ( !fileCache ) break
     for (const link of fileCache.links) {
       const linkPath = app.metadataCache
         .getFirstLinkpathDest(, p.file.folder)?.path
       // console.log("    link: ",, linkPath == currentFile)
       totalInlinks += linkPath == currentFile
   return [, p.file?.inlinks?.length, totalInlinks]

if ( result.successful ) {
  dv.table(["Note", "NoteCount", "TotalCount"], result.values)
} else
  dv.paragraph("~~~~\n" + result.error + "\n~~~~")

In my test folder this returns the following:

Which indeed is the correct totals, as the first file holds three different links to the “Two inlinks” file, and “One inlink” also links to that file, making the total four.

So it’s possible to get this count, but whether it’s worth it to switch to dataviewjs for it that’s another debate. :smiley: