Summing the number of file.outlinks from multiple pages

I’ve been scratching my head for a couple of days regarding this issue but all the forum topics I visited just didn’t quite fit.

What I’m trying to do

I would like to know how to sum up the number of outlinks from multiple pages, and assign it to a metadata field so that I can display that field on any other page I want.

Things I have tried

I’m able to display all the outlinks using this code:

table without id
	file.link as "Skills",
	length(file.outlinks) as "Hub Notes Total"
where lower(skill-type) = "intelligence"

I’m not sure how to then sum up this length from each row for display.

I also tried having a metadata for each of those pages as hub-notes-total :: = length(file.outlinks) which show the number of outlinks correctly, but I found that when I try to then use sum(rows.hub-notes-total), instead of taking the value, it takes the actual programming text =length... and then throw me an error.

Hi @Baconbec , welcome to the Obsidian community!

Summing the number of outlinks matching your query can be done a few different ways. My favorite is to use FLATTEN to put each outlink in its own row, then use GROUP BY to roll them all up into one field. Here’s a query that I think will do something similar in your vault:

```dataview
TABLE WITHOUT ID
    length(rows.Outlink) as "Hub Notes Total"
WHERE lower(skill-type) = "intelligence"
FLATTEN file.outlinks as Outlink
GROUP BY ""
```

This produces output like the following:

Unfortunately, so far as I know, it is not possible to assign the result of a Dataview query to a metadata field or inline field. You’ll need to put the query itself on whatever page you want to display it on.

Hope this helps,

Craig

1 Like

Awesome, thanks for the help @Craig :slight_smile: This works for what I’m trying to do. And good to know the limitations on the metadata field and dataview query as well.

1 Like

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