All my notes contain a header called “Developments”. In this section I have a bullet list. Each bullet is a date, the children for each date contain some comments on things that happened that day. What I would like is for a script to gather bullets that contain the name of the current note, across all notes, and sort them into a new list based on the parent bullet’s date.
Things I have tried
What I have currently is a piece of code:
list without id [bullets.text, bullets.children.text]
flatten file.lists as bullets
where meta(bullets.section).subpath = "Developments" and contains(bullets.children.text, this.file.name)
sort bullets.text asc
This works reasonably well, I get a sorted list that contains the correct bullets, nested under the parent date. The list seems sorted based on said date. However, two things are still not to my liking:
Bullets from the same date, but coming from different notes, will not be grouped together (I’m aware I never asked it to, but when I’m trying to use “group by bullets.text”, it will mess up the whole thing and turn it into a list of empty bullets).
The date bullets will have an additional bullet in front of it, as will the first bullet of the children of that date bullet.
Can you please give me some advice on how to fix these two issues?
I’m away from my computer, so the following code is untested, but since v0.5.56 of dataview there is a new function flat() which can reduce the item levels, so maybe the following will help you on your way:
```dataview
list flat(bullets.children.text)
flatten file.lists as bullets
where meta(bullets.section).subpath = "Developments" and contains(bullets.children.text, this.file.name)
sort bullets.text asc
Group by bullets.text
```
Thanks for your question. So I have several notes in the vault. Each note looks something like this
Developments
2023-06-14
Some [[topic]] here.
Some more text here
2023-06-15
Some [[topic]] here.
Some more text here
2023-06-16
Some [[topic]] here.
Some more text here
So imagine we have several notes that have their own bullets and dates.
Say I’m in the [[topic]] note. Here I want to get an overview of all these bullets that mention [[topic]], and display them in chronological order, like so:
2023-06-14
Some [[topic]] here.
[[topic]] mentioned in another note.
2023-06-15
Some [[topic]] here.
[[topic]] mentioned in another note.
2023-06-16
Some [[topic]] here.
[[topic]] mentioned in another note.
But right now, I’m getting the following:
Note A
2023-06-14
Some [[topic]] here.
2023-06-15
Some [[topic]] here.
2023-06-16
Some [[topic]] here.
Note B
2023-06-14
[[topic]] mentioned in another note.
2023-06-15
[[topic]] mentioned in another note.
2023-06-16
[[topic]] mentioned in another note.
I hope this helps explain what I want, and that it’s somehow possible to achieve this.
```dataview
LIST rows.topicText
FLATTEN file.lists as item
FLATTEN filter(item.children, (l) => contains(l.outlinks, this.file.link)).text as topicText
WHERE meta(item.section).subpath = "Developments"
AND regexmatch("\d{4}-\d{2}-\d{2}", item.text)
GROUP BY item.text
SORT key ASC
```
The trick to this query is looking at the right context. Instead of looking for the children, and getting the parents (which are somewhat unknown), we can look at the parents and filter out the wanted children (Which out of context sounds really bad… ).
Therefore we split the lists into item, look for any item in the correct section which is a date, aka a parent, and for those items we filter out children having a link to the current file into topicText. Now we’re ready to group and sort on the date, and present the result from each of the rows.topicText.
Do note that this solution looses out on the origin of the topic text, but that could possibly be added back in as an addition/alteration when building the topicText.
This works amazingly like I described! Thank you so much. But you’re also right that it could probably do with some link back to the original note. How would you adjust it to include the link to the note (in the form of the note’s name) in brackets at the end of each bullet?
```dataview
LIST rows.topicText
FLATTEN file.lists as item
FLATTEN filter(item.children, (l) => contains(l.outlinks, this.file.link)).text as topicBase
FLATTEN topicBase + " (" + file.link + ")" as topicText
WHERE meta(item.section).subpath = "Developments"
AND regexmatch("\d{4}-\d{2}-\d{2}", item.text)
GROUP BY item.text
SORT key ASC
```
Untested, but hopefully it works. It’ll first pick the children text as topicBase, and then append the file.link within brackets to build up the topixText.
This worked like a charm. You sir, are a hero! Do you have any good references for building these queries? I find that the documentation I came across so far does not fully give one enough information to understand all the possibilities and data structures and so on.
The best tip I think I can give is keep trying, and try to reformulate your request in terms of which constructs you know exists already.
Like in this case I knew children existed, so I reformulated it to look for parents where I could filter out the children texts.
This goes in iterations between reformulating, recognising what can be done, and getting the issue at hand down to known building blocks.
So keep trying, and often it’s also wise to build a massive table with all (and then some) needed information, before chipping away to just get result you’re wanting.