Creating a Calendar Query to Track Completed Tasks

Things I have tried

I have tried cutting, pasting and editing sample code found online but I haven’t found anything directly related to what I am trying to do. I’ve read the FAQ for Obsidian and DataView but I’ve only found indirect references to displaying calendars as a query output. I have managed to create a simple query that displays as a calendar but I can’t get it to display any information related to my daily note. I found a DataView tutorial on DataView queries by Nicole van der Hoeven, but it also didn’t cover the finer details of the calendar query.

What I’m trying to do

I want to create a query that produces a calendar indicating which days have a specific Task marked completed (ex: -[X] Caffeine free). This would fulfill the minimum requirements. It would be better if it marked an open dot for dates with an incomplete tasks by that name and a solid dot for days when the task is completed. A further goal would be to output the length of the current streak and the length of the longest streak without an incomplete task.

I’ve not used CALENDAR queries, but I played around a little with it, and discovered that what it displays is kind of similar to a LIST output, so in my testing I did stuff like:

```dataview

LIST file.day
WHERE file.folder = this.file.folder
WHERE file.day
```

## Calendar query

```dataview
CALENDAR file.day
WHERE file.folder = this.file.folder
WHERE file.day
```

With the output of:

It could actually be a LIST WITHOUT ID, but for test purposes I prefer keeping it as a LIST.

So in order to get your query to show up as dots, you need to make sure you get a list of dates, so I added a few tasks like your example into my test files, and fiddled around until I got the list correct, and then tried that as a CALENDAR:

### First as a LIST
```dataview
LIST file.day
FLATTEN file.tasks as T
WHERE file.folder = this.file.folder
WHERE file.day AND
  T.completed and
  T.text = "Caffeine free"
```  


### Then as a CALENDAR
```dataview
CALENDAR file.day 
FLATTEN file.tasks as T
WHERE file.folder = this.file.folder
WHERE file.day AND
  T.completed and
  T.text = "Caffeine free"
``` 

Which produced the output:

Other denotation and streaks

I don’t think the CALENDAR query is very useful for getting streaks, nor doing alternate decorations if tasks are not done, and so on. I think what you see is what you get, and that you’re not getting a whole lot more.

For stuff like that maybe the Tracker plugin is a better tool for the task. I’ve not used that myself, and I see occasional posts related to both using that plugin, and to do queries not using that plugin. So I’m kind of uncertain as to how good of a tool it is.

My only reference to using it is that I can’t get the pie chart functionality to work, and it seems like it is not under active development. That doesn’t mean it doesn’t work, but then again it’s not a good sign. It does have the capability of showing streaks though, and other stuff which I’ve not looked that much into.

PS! I’m showing the LIST queries here, but that is just a guide when setting up the CALENDAR query. When you’ve got it going, the LIST query can be removed.

2 Likes

I was thinking of the calendar as a different function nd not just a different out put of the same query results. Your code works and is a good start. Thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.