Dataview Queries in Automated Notes
I have had some people ask me about the obsidian dataview queries I use in my weekly and monthly notes to accumulate section entries, so I thought I would take a minute to address what I have been doing to make things work the way I want. Before I go into the specifics, note that I have cobbled these queries together from what others have done, and I am sure there are better and more efficient queries to accomplish the same goals. But this works.
Weekly Dataview Queries
TABLE WITHOUT ID
file.link AS "DailyNote", entry AS "Entry"
FROM "001-Journal"
WHERE entry != null
AND file.day.year = number(substring(string(this.file.name), 0, 4))
AND file.day.weekyear = number(substring(string(this.file.name), 6, 8))
SORT file.day
I don’t use the weekly note as much after having created my monthly notes, but I’ll address them as the queries are interesting. The above dataview query is used to pull journal entries from daily notes into the “Journal” section of the weekly note. Line by line:
- TABLE WITHOUT ID - Creates a table without auto generated column headers
- file.link AS “DailyNote”, entry AS “Entry” - Column headers with the daily file name being the ‘DailyNote’ column and a journal entry on a daily note identified with the inline YAML entry of ‘::entry’ listed in ‘Entry’ column. (I spoke a bit more about how I use inline YAML entries here.)
- FROM “001-Journal” - Selects notes from the journal folder ‘001-Journal’ folder in my obsidian vault.
- WHERE entry != null - Selects all lines that have the inline YAML tag ‘::entry’.
- AND file.day.year - number(substring(string(this.file.name), 0, 4)) - My weekly file names are in the format YYYY-WXX. This entry selects the year from the filename.
- AND file.day.weekyear = number(substring(string(this.file.name), 6, 8)) - Given the weekly file name format, this line selects the week.
- SORT file.day - Sorts retrieved records by day oldest first (my pref).
I use the same dataview query for the Journal, Accomplishments, Highlights, Links, and Gratitude weekly notes section. All that needs to be changed are the appropriate entries in lines 2 and 4 of the query.
Monthly Dataview Queries
TABLE WITHOUT ID
file.link AS "DailyNote", entry AS "Entry"
FROM "001-Journal"
WHERE entry != null
AND file.day.year = number(substring(string(this.file.name), 0, 4))
AND file.day.month = number(substring(string(this.file.name), 6, 7))
SORT file.day
The monthly note dataview queries are very similar to what is in used in the weekly notes for most sections with the exception being that the month is selected instead of the week in the 2nd AND clause (line 6).
Completed To-Do Items
done <% tp.date.now("YYYY-MM").format("YYYY-MM") %>
sort by done date
hide backlink
hide priority
hide due date
hide scheduled date
hide start date
hide recurrence rule
hide tags
hide edit button
hide task count
I have a section listing all monthly completed to-do items in my monthly note. I use the Tasks plugin for Obsidian, and the above Tasks query retrieves items done in the current month. When the monthly note is initially generated, Templater inserts the year and month into the first line of the query.
Thoughts
As I said before, I am fully aware that my queries are not fully optimized. I’ll probably need to take a look at that as my Obsidian vault grows. For now, it all seems to work pretty well, and the setup gives me the information that I want where I want it.