Not currently, no. If this isn’t already a feature request, I think it’s a great idea to post!
I’ve been looking all over for how to query around nested tags.
For instance, I may have a bunch of notes to aggregate Standard Work for my teams, but those will have nested tags. For a MOC page, I may want to create a list of all the Standard Work pages I have in my vault, inclusive of all of the nested tags. A way I would think I could write that is:
list from #standard-work/**
But I can’t find an ergonomic way of writing a query like this which doesn’t require me to where-clause against every known case of nested tag which is more static than I’d like. (I don’t want to update this page every time I add a new nested tag).
Any thoughts in the community?
Just to clarify, your questions says “I may want to create a list of all the Standard Work pages I have in my vault, inclusive of all of the nested tags”. So you want to list every page tagged with #standard-work
and also every page tagged with #standard-work/something/maybeMore
?
This snippet should do that:
list from #standard-work
Dataview already matches nested tags, so that list from #Tag
should match #Tag
as well as #Tag/sub
This ability to add the Backlinks and Index is awesome! Thanks.
Has anybody tried the GROUP BY
? I tried that but didn’t get the expected result.
For example, say I have some notes with the tags #Note/Author, #Note/Principle, #Note/Concept…how can I group all the results with tag #Note according to their subtags?
Could anyone help?
I actually hadn’t figured it out myself, but your question made me give it a go. I think I’ve got it…
So, I’m gonna use an example:
In each of my assignments, I have a field (intensity
) with a red, yellow, or green square telling me how much work will be required.
So, if I want to group all of my assignments by their intensity, I do the following.
First, gather all the assignments:
FROM #Assignments
Then, group by intensity
:
GROUP BY intensity
rows
Object
Now, here is the part that confused me… by grouping them, you’ve now got a new object created by the grouping. This is a nested list of all the assignments grouped by intensity. So something like:
[
[A1, A2, A6], // Green
[A3, A4], // Yellow
[A5, A7] // Red
]
The way you access this new list is with the rows
object.
So if I want the file name of every note in the array, I call rows.file.name
.
If I want the dueDate
of each note in the array, I call rows.dueDate
.
In this example, I call the title
property (rows.title
).
Now, you sorta have to change the ordering around, but it should still make sense.
TABLE intensity, rows.title
FROM #Assignment
GROUP BY intensity
Which gives me this, as desired:
So for your example, you want to group files by subtag. Can you try this and let me know what you get? I think the output will be a little messy, because it repeats alot of the tags, but it should still group them as you want.
TABLE rows.file.name, rows.file.tags
FROM #Note
GROUP BY file.tags
Also, it will only consider two notes to be in the same group if they have exactly the same tags. So even if two notes have #Note/Author
, if the one has a tag that the other doesn’t, I don’t think they’ll be grouped together.
wow @SkepticMystic Thank you so much for your elaborate and earnest answer! It does help a lot!
It is the rows Object that confused me too, and you’ve made it so clear. I tried replacing the rows.file.name with rows.file.link under your instruction, and now it works quite perfectly.
Just to let you know you helped me solve the long time problem.Thanks so much again!
Is there a way to show the number of result rows ?
I’m really glad to hear it helped!
Thank you for getting me to finally figure out how group by
works
I tried a hacky method which didn’t seem to work.
I thought to use length()
or sum()
, but each of these only works as a test in a where
block; it doesn’t give a returnable value.
I think this would be really useful though. Check if it’s an existing feature request and give it an upvote, otherwise make a new post for it
For now, you could totally pair dataview with the Obsidian Query Language plugin (OQL).
After your dataview table/list, put an OQL codeblock underneath it to show the {count}
of the same query.
Source
Thanks a lot for your help.
I also tried to play with Group By
and ‘sum’ and ‘length’ functions but like you said, it doesn’t seems to work in this context.
I thought that OQL’s queries only rely on folders… I will check the doc again to see if it works also with yaml frontmatter metadata.
I haven’t used OQL very much, so its definitely possible that it doesn’t allow querying on the same objects as dataview.
But I think this would be a useful feature to request in a future update
So your post got me thinking alot, and I think I’ve figured out a workaround for seeing how many results get returned!
This CSS snippet will number the rows of a dataview table:
.table-view-table {
counter-reset: section;
}
.table-view-table > tbody > tr > td:first-child::before {
counter-increment: section;
content: counter(section) ". ";
}
Resulting in something like this when you make a table:
Wow, I’m silly.
Maybe it had something to do with how it appears queries are cached, so I may have made an update to a nested tag and expected a result to automatically appear which I now see isn’t the case (and totally understandable).
Simple oversight, thank you for responding
Nice solution, but are you sure it is correct? I tried it and it just gives number 1 to all the items on the table.
You can get the value using length()
; I got the number of files tagged #Ticket
like so:
TABLE length(rows) as ticketCount
FROM #Ticket
GROUP BY true
It was a little tricky to figure out the summing, but I got that as well. Here’s what I use to see how many points I’ve accumulated in my #Tickets for the current Sprint, as well as how many more I need to hit my current goal of 10:
TABLE sum(rows.Points) as TotalEarnedPoints, 10-sum(rows.Points) as PointsToGo
FROM #Ticket and [[Sprint Ending 2021-04-08]]
WHERE Ended != null
GROUP BY Sprint
Huh, I mean its still working for me. What theme are you using? Did you add it to the main.css, or as a snippet?
So it’s definitely targeting the right element if you see the numbers in the right place. But it seems its not incrementing the value properly. That’s what the counter-increment: section;
is for.
Nice! I was missing the fact that you have to give the length(rows)
value an alias! as whatever
.
I also like the summing method, good catch
I am using it as a snippet, I am using Minimal theme with some other snippets from here:
yeah , it is definitely doing something right. or maybe it is because one of the plugins , it is hard to tell