Bases: Property listing number of files listing to my file

What I’m trying to do

I have a base which lists all my “Author” notes. This is simple, as they are all tagged with #author. Now I would like to create a property with a formula, that counts the number of notes which link to the respective Author notes. Alternatively, the formula could also count all notes where the author property in the yaml is equal to the note title. This is what such a note could look like:

---
author: Stanislaw Lem
---

# The Albatross by [[Stanislav Lem]]

...

So if I have seven notes listing Stanislav Lem as author, respectively linking to him, the author.base would show something like

Author ……………………… Works
Stanislav Lem …… 7

Progress so far:

Solved the part with the Links:

file.links.length

But how would I get it to work if had only the author property and no link?

1 Like

Links part is not solved, I get a wrong count.

Hello

Are you getting a count of 13? Querying ‘length’ returns the number of characters in the value of the given property.

If author: Stanislaw Lem is a text property, the Bases below should show a total count of the files that contain the property.

## B1

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - author == this.author

```

##B2

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - author == "Stanislaw Lem"

```

1 Like

If all your “book notes” are linked to their respective “author notes”, you could try to use file.backlinks, I think :thinking:

But that could depend on how you structured your book/author relationship :blush:

I mean, using solely:

file.backlinks.length

… could be enough but if you want to make sure the author’s key within the “backlinked notes” match the author, you could use something like:

file.backlinks.filter(value.asFile().properties.author == file.name).length

or

file.backlinks.filter(value.asFile().properties.author.contains(file.name)).length

But again, that might not be necessary :blush:

Something similar could also potentially work using file.links instead (depending how your book/author relationship is setup) :blush:

Some things to note here though:

  • This is just a very quick test :sweat_smile:
  • I’m assuming you’re using the latest catalyst release of Obsidian (1.9.7) :blush:
  • In the example you shared, the value of the author key in the book note is “Stanislaw Lem” (Stanislaw, ending with a “w”) while the note point to “Stanislav Lem” (Stanislav, with a “v”) :innocent: … which could be problematic but that could also just be a copy/paste here thing :blush: .

file.backlinks.filter(value.asFile().properties.author == file.name).length

works for me, thanks a lot!

1 Like

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