How to count the number of custom inlinks? (and show it in a table)

The problem:

I write down all my tarot card readings in Obsidian. I’d like to make a table that lists all of the cards and shows me the number of times each card has showed up in my readings so far.

What I have so far:

  • Each tarot reading links to individual cards that show up in it AND it has property “spread”
  • Each card has it’s own file and property “tarot-card”

I use dataview to generate a list of all the readings in which a card has showed up. Sometimes files other than readings link to individual cards so for now, this is how I find only relevant inlinks:

LIST
WHERE contains(this.file.inlinks, file.link) AND !contains(this.file.outlinks, file.link) AND spread
sort file.name DESC

If I make a basic table with all of the inlinks, the data simply isn’t true to what I need. Is there a way to combine the above List dataview with the Table dataview in order to get an accurate number?

TABLE length(file.inlinks) as "Times pulled"
WHERE tarot-card
sort length(file.inlinks) DESC

Example of what it does now:

The Devil has 12 inliks, which is technically true but…

The number of relevant inlinks (inlinks from files with property “spread”) is only 7

So again, how can I get it to show the number of inlinks as only 7 in the table view?

I’m not quite sure I fully understand your use case, but it seems like to want the “Times pulled” to check which of the current files inlinks has the “spread” property. This can be achieved through filtering the file.inlinks using filter(), and store this into another variable for later work. Maybe something like the following might do the trick:

```dataview
TABLE tarot-card, length(spreadInlinks) as "Times pulled"
FLATTEN list(filter(file.inlinks, (inlink) => inlink.spread)) as spreadInlinks
WHERE spreadInlinks
SORT length(spreadInlinks)
```

Here I use:

  • FLATTEN list(filter( file.inlinks, (inlink) => ... )) as spreadInlinks – This recreates a list of the filtered items from file.inlinks, after looping on each of the inlinks as inlink in the following expression. Due to how FLATTEN normally expands a list into single items, we use list( ... ) to gather it back into a list again before storing the result
  • inlink.spread – Not sure if this is the correct filter, but this one should check if that particular inlink has the spread property, and that it returns a truthy result

If you don’t care for the actual results of the inlinks, you might consider doing length( filter( file.inlinks, ... )) and just use the length in the other expressions.

Update: corrected a typo…

Hi! Thank you for answering! I was actually hopping you specifically would see this post! :smile: I kept digging up old posts and trying to come up with correct code from your replies to other people. I figured that I’d need flatten and filter but I couldn’t get it to work.

Unfortunately, I’m getting parsing error with your code too, but I think your idea is correct.

Tried writing WHERE length… separately, still got an error. I don’t understand what’s incorrect in either of those…

Just to make sure we’re on the same page “it seems like to want the “Times pulled” to check which of the current files inlinks has the “spread” property.”

I want a table that lists all 78 of the tarot cards (each has property “tarot-card” and in the 2nd column I want “Times pulled” to count the number of inlinks for each card that have “spread” property. So basically it should look like the first picture in my original post.

I updated the query which had a typo in it. Try removing the first time it says WHERE.

Okay, so now the “Times pulled” is correct! BUT it’s also listing files that don’t have the tarot-card property. Can I remove those somehow?

It’s harder to write queries you can’t test… :slight_smile:

Try this one:

```dataview
TABLE length(spreadInlinks) as "Times pulled"
WHERE tarot-card
FLATTEN list(filter(file.inlinks, (inlink) => inlink.spread)) as spreadInlinks
WHERE spreadInlinks
SORT length(spreadInlinks)
```

No no That’s perfect! Thank you so much! :smiling_face_with_three_hearts:

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