What I’m trying to do
I want to get the number of per tags within notes.
I’m scraping and writing headline news every week.
And I’m using tags to organize each news.
like
(the name of this note file is “T 2024-W14”)
And in other notes, we use dataview to manage notes written every week.
As I said above, I would like to add the number of each tags I wrote in each note as a column.
In fact, if I search with tags within obsidian, I can see how many tags exist for each note.
So is there a way to show the number of each tag with dataview or dataviewjs?
Things I have tried
I tried referring to the following links
Official Document
Can I use the Dataview to COUNT the number of tags within a note?
How to COUNT number of times a tag appeared in notes from my Journal?
Count each tag in a single document
(and more…)
I got the results,
However, it wasn’t what I expected, because this is not the number per tag, it’s just the number of unique tags.
1 Like
You can do an inline query with Dataview!!
You can write
you have to put `
around it so it recognizes the code and remember the .length
otherwise it shows the notes individually. Replace `#important’ with whatever tag you like, it outputs a number.
For example:
Edit: Just realized, I misunderstood what you were asking for. Sorry!
Oh, thank you for your reply.
It’s not what I wanted, but that’s a pretty good idea.
I think it may be possible to use the dataviewjs with your suggestion.
I don’t know the grammar of dataviewjs properly, so I roughly wrote it in pseudo code lol
```dataviewjs
dv.table(
["Number of tags"],
for page in dv.pages("directory")
for tag in page.tags
page.map(p => p."tags".length)
);
```
How is it?
Doesn’t it look a bit plausible?
Is there anyone who can help me?
holroy
April 8, 2024, 6:51am
4
The ordinary approach using file.tags
or file.etags
will only report any tag used in a given page just once, so you’ll need to go deeper and use some variant of app.metadataCache.getFileCache().tags
as illustrated in this post:
I kind of had given up on getting the complete lists of tags, and was about to write a post on how you would need to change into using inline fields to be able to gather all the various tags. Then I read this post where they utilise app.metadataCache.getFileCache().tags, which was a function I was wondering about existed but hadn’t located yet.
I then proceeded to build some test files, and in the main file I had these queries:
---
Tags: f75210
---
questionUrl:: http://forum.obsidian.md/t//752…
I’m a little busy a few days now, but are you able to take it from there, or do you need help with the coding?
I referred to the this post and used the following code,
```dataviewjs
const topicFiles = dv.pages('"Some pages"')
.flatMap(p => {
const tFile = app.vault.getAbstractFileByPath(p.file.path)
const allTags = app.metadataCache.getFileCache(tFile).tags
return allTags
})
.map(t => t.tag)
.groupBy(t => t)
.map(t => {
return [ t.key, t.rows.length ]
})
dv.table(["Title", "Numtags"], topicFiles)
```
I got this
and this results matches the number that comes out when searched with tags!
We’re almost there…
finally, I would like to see the calculated value for each note, rather than flattening all the notes together.
Is it possible?
1 Like
holroy
April 9, 2024, 4:06pm
7
What do you mean with calculated value for each file?
As I said at the beginning, there are several tags in a single note.
And there are a lot of these files
This result is to count the tags in all these files together.
I want to see the number of tags separately for each file
(for example…)
system
Closed
July 10, 2024, 12:44am
10
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.