Dataview Tasks by Completed Year

Hello.

Is there a way to only list tasks by their completed year? Simple example below:

- [x] Done [completed:: 2024-04-10]
- [x] Also done [completed:: 2025-04-10]

```dataview
TASK
WHERE file.name = this.file.name
AND contains(file.lists.completed, "2024")
LIMIT 50
```

With thanks :smiling_face:

Almost there! :smiling_face:

This one works for me:

```dataview
TASK
WHERE file.name = this.file.name
AND contains(text, "completed:: 2024")
```

Cheers, Marko :nerd_face:

1 Like

Do you want them in their own section? Like in this variant:

- [x] Done [completion:: 2024-04-10]
- [x] Also done [completion:: 2025-04-10]

```dataview
TASK
WHERE file.name = this.file.name
GROUP BY completion.year
LIMIT 50
```

Updated: Should have used completion

2 Likes

Thanks @DiCaver and @holroy.

Marko’s code works for my needs—essentially trying to filter completed tasks into years rather than having a massive long list of all tasks for all years.

Why is it necessary to use contains(text … rather than using the actual key alone? And how should I know to use text in such a situation? I could not work out what to do from reading the Dataview docs. My bad, I know. Just wish I had better logic to know what to do and when to do it. Despite using Dataview for years and having read the docs relentlessly, I still struggle. :sob:

I misread your request to sort according to year, not as to limit to that year. For the latter it would be better to do WHERE completion.year = 2024.

If you work with text you’re working with the entire line, which sometimes is useful if the information you want to look at hasn’t been extracted already. But most often it can also be accessed using other means like in this case through the completion date field.

Updated: Should have used completion

Thank you.

I must be doing something wrong as I can’t get completed.year = 2024 to return any tasks.

- [x] Done [completed:: 2024-04-10]
- [x] Also done [completed:: 2025-04-10]

## Text

```dataview
TASK
WHERE file.name = this.file.name
AND contains(text, "completed:: 2024")
LIMIT 50
```

## completed.year

```dataview
TASK
WHERE file.name = this.file.name
AND completed.year = 2024
LIMIT 50
```

Hehe, the devil is in the details—by accident! I saw this. The word should be completion instead of completed. Then @holroy’s solution works. At least by this: Metadata on Tasks and Lists - Dataview. completed is boolean.

```
- [x] Done [completion:: 2024-04-10]
- [x] Also done [completion:: 2025-04-10]


## completion.year

```dataview
TASK
WHERE file.name = this.file.name
AND completion.year = 2024
LIMIT 50
```

Cheers, Marko :nerd_face:

3 Likes

Sorry about that… Marko is very correct that the date field is completion, and completed only is used as a boolean to check whether a task is finished or not. So in all my previous responses, they should’ve used completion.

NB: If you actually use completed as an inline field it might be overwritten by dataview as that is set when rendering. This might also not allow for the completion field to be set correctly. (Which is part of the reason I use the checkmark/emoji to set this date)

2 Likes

Again, @DiCaver and @holroy, many thanks for the help and explanations.

Lost count of the number of times I have read Metadata on Tasks and Lists and seen both completed and completion and failed to register that they were being used differently.

I don’t ever write the completion field / date – when I click the Dataview query to mark the task as complete, Dataview writes the details into the original task automatically. Just seen that I can set the Completion date format in Dataview’s settings. Will change it from completed to in line with your advice.

Indebted to both of you. :pray: :purple_heart: :four_leaf_clover:

1 Like