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…
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.
Hi! Thank you for answering! I was actually hopping you specifically would see this post! 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.
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.
```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)
```