I have a plenty of lines within my vault, with a date in it in YYYY-MM-DD format, for example:
- 2024-10-18 contacted, did, noted...
I would like to have all those lines to be shown within one file.
Things I have tried
Searched within the forum, but I only found a solutions for the tasks with status - like created, complete, etc.
In my case it’s not a proper task - it misses the complete structure and tags, but it has a date in predefined format, that matches the file name format for the day note.
Few things I’ve tried:
LIST WHERE regexreplace(this.file.name, "-[01][0-9]", "") = dateformat(file.day, "yyyy-'W'WW")
LIST WHERE date = this.file.day
TABLE filter(prompt, (p) => contains(p, "04/02")) as Prompts
WHERE prompt
It’s not that I understand how it works, so it was mostly monkey’s copy-paste job with trying to make some sense.
Yes, this is possible using Dataview. Although we can’t query list items directly using e.g. LIST, we can still access them through FLATTEN.
Data
Suppose we have two files in our vault of interest:
# Page 1
- 2024-10-16 Test 1
- 2024-10-17 Test 2
- 2024-10-18 Test 3
- Some other list item
# Page 2
- 2024-10-16 Test 4
- 2024-10-17 Test 5
- 2024-10-18 Test 6
- An unrelated list item
List all items
We can use a simple query to pull out all the list items, and show only the ones that start with a date:
```dataview
LIST Item
FROM "Scratch"
FLATTEN file.lists.text as Item
WHERE regexmatch("^\d\d\d\d-\d\d-\d\d .*", Item)
```
In this query, the FLATTEN command splits each row up, creating a new row for each list item on the page. Then the WHERE clause filters out any rows that don’t start with a date.
Group by page
If you want to group the list by page, you can do so by adding a GROUP BY command and making a small change to the LIST clause:
```dataview
LIST rows.Item
FROM "Scratch"
FLATTEN file.lists.text as Item
WHERE regexmatch("^\d\d\d\d-\d\d-\d\d .*", Item)
GROUP BY file.link
```
The GROUP BY command tells Dataview to return a new set of rows, one for each group, with each one containing the results for that group. So we have to update the LIST clause to tell Dataview we want to see the Item for each subrow.
Further extending (with a slight variation) on Craig’s work, here are two queries which also focus on a given date.
A general query listing all related to a date
```dataview
TABLE rows.theText as Lines, rows.file.link as Origin
WHERE file.folder = this.file.folder
FLATTEN file.lists as item
FLATTEN date(substring(item.text, 0, 10)) as theDate
FLATTEN substring(item.text, 11) as theText
WHERE theDate
GROUP BY theDate
```
In this query I assume the item.text has a date at front, using substring to pick that date part. And later on with WHERE theDate I verify the truthfulness of that assumption. I then group by this date, and display the origin of lines for a given date.
Using the same test data as Craig, in a Norwegian locale it presents the following output:
Within a daily note
The second query lists all lines related to that daily note. So if you had a daily note like 2024-10-17 Something else.... (where the key part is the date somewhere in the file name), you could use this query:
```dataview
LIST WITHOUT ID theText + " (" + file.link + ")"
WHERE file.folder = this.file.folder
FLATTEN file.lists as item
FLATTEN date(substring(item.text, 0, 10)) as theDate
FLATTEN substring(item.text, 11) as theText
WHERE theDate = date(this.file.day)
SORT theText
```
Which would produce this output:
Note especially how I produced the text for output at the first line of the query by combining the theText and file.link to get the origin of that line. Here you could of course do whatever you like.
@Craig , @holroy , thank you very much! I’ve heard a lot about warm and helping Obsidian community, but didn’t expect that level of assistance and - most of all - speed - thank you for you prompt response!
And apologies for my delay in getting back to you - I got pushed back by other things, hoping to get back here now.
I would like to ask you a bit more of the questions, if you don’t mind?
Is there some documentation / source code - to read on how to create such a queries? I have tons of questions that I don’t feel fair to dump on you…
Is there any way I can reduce search for the text files to process only to a specific folder?
In my specific case, I have a folder tracking some of the things, and I would like strings that have date from ‘Natural Language Data’ extension (YYYY-MM-DD format) to appear in my daily notes - hence extracting items from other notes to appear in my daily note / review.
First, yes, you can read a lot about Dataview at its official documentation site, which lists its data commands, literals, expressions, functions, and more. You can read more here:
To reduce your search to a specific folder, use the FROM directive. In the example below, the FROM statement tells Dataview to only consider notes in the “Scratch” directory. You can use FROM to select folders, tags, single files, and more.
```dataview
LIST rows.Item
FROM "Scratch"
FLATTEN file.lists.text as Item
WHERE regexmatch("^\d\d\d\d-\d\d-\d\d .*", Item)
GROUP BY file.link
```