Counting tasks with a certain tag?

Things I have tried

Searched help files and this forum, no exact use case. I use Dataview and Tasks extensively, but I am not IT savvy. I found how to derive # of active tasks on a given page, but since my project pages have queries rather than actual tasks, it doesn’t help.

What I’m trying to do

How can I derive a count of active (=not completed) tasks with a certain tag?

I tag my tasks with a project name. It’s more convenient for me vs a project-dedicated page, as I tend to take notes in a scattered way, eg. I can add a task to a literature note, or to daily notes, or to a quick one-liner note.

When Tasks lists my tasks (not completed and description includes #tag-of-interest), it gives the number I need after the list, but how to get this number as a separate value?

I’m trying to build a dashboard where I could have a project and # of open tasks per project. Can’t figure out how to get to this count.

A few tricks you can apply:

Result:

image

Code

`= "<progress value='" + (length(filter(this.file.tasks.completed, (t) => t = true)) / 150) * 100 + "' max='100'></progress>" + "<br>" + round((length(filter(this.file.tasks.completed, (t) => t = true)) / 150) * 100) + "% total completion"`

`= "<progress value='" + ((length(this.file.tasks)) / 150) * 100 + "' max='100'></progress>" + "<br>" + round((length(this.file.tasks) / 150) * 100) + "% traits added"`

Current total:  **`=(length(this.file.tasks))`**
Done total:  **`=(length(filter(this.file.tasks.completed, (t) => t = true)))`**

I forgot, but if I’m not mistaken this is by using the Dataview plugin with these settings on:

5 Likes

Hi.
To better understand your goal and the way to achieve it, please add more information:

  • tasks examples (if #tag in the task text or in a specific inline field key in the task);
  • your desired output (a table mockup);
  • your tasks query.
1 Like

Thanks so much, I’m sure this will help others! For my use case, that won’t do, as my tasks are not on the same page.

Thank you.

Tasks scattered across vault, i.e. in different notes. Format:

  • [ ] #project-name-1 add this feature, due date 2022-05-11
  • [ ] #project-name-2 correct this error, due date 2022-05-12

Desired output: (open meaning not done)

Open tasks that include #project-name-1: 1
Open tasks that include #project-name-2: 1

My current task query: doesn’t exist, I can’t figure that out. If I query like below, I get the task count under the output, but also the entire list of tasks. I just need the N.

not done
description includes #project-name-1
1 Like

Also interested in this

2 Likes

There’s a tag filter or Tasks that works similar to description:

Combine with the not done filter:

By default, the Tasks code block outputs the count of tasks that match the query below the list of tasks.

I do the same thing on my project pages because I also capture tasks when they occur on different daily notes and contexts. This is my working Tasks query block:

description includes ABC
not done

ABC is essentially my unique code for a specific project, so this searches my entire vault for any Tasks that are not done that have that string. (Tag and Description would work the same in this example.)

1 Like

Sorry, just seeing this now.
I’m daft: can you explain how come you only get number of tasks but not the task themselves? You can see in my initial message that I use exactly the same query.

Topic

Summary

1.How to distinguish list items or task items from the file.lists data?
3.How to filter by a task item which contains a tag?
4.How to count a task item which contains a tag?
5.How to display the result as a list?


Test

Summary
  • dataview: v0.5.41

Input

Summary

dictionary files

  • filename : dic_20120201
---
Date: 2012-02-01
---
## input
### input_m:  milestones
- 2012-02-01 Started learning Javascript  #Test/d01 [[Note J]] , [[Note K]]
- 2012-02-02 Wrote a "Hello world" script, and it worked! #Test/d02 [[Note J]]
- 2012-02-03 Learned how to fetch data from a URL #Test/d03
- 2012-02-04 Learned about Promises #Test/d04
- 2012-02-05 Learned about await/async #Test/d05[[Note K]]
- 2012-02-06 Started working with NPM libraries #Test/d06
- 2012-02-07 Published my first code to Github #Test/d07
- 2012-02-08 Published my first code to Github


### input_t: tasks
- [ ] 2012-02-11 add this feature_A  #Test/d01 [[Note P]] , [[Note Q]]
- [ ] 2012-02-12 add this feature_B #Test/d02  [[Note P]]
- [ ] 2012-02-13 add this feature_C #Test/d03
- [x] 2012-02-14 add this feature_D #Test/d04
- [ ] 2012-02-15 add this feature_E #Test/d05 [[Note Q]]
- [x] 2012-02-16 add this feature_F #Test/d06
- [x] 2012-02-17 add this feature_G #Test/d07
- [ ] 2012-02-18 add this feature_S  %%[created:: 2012-02-18]%%
- [ ] 2012-02-19 add this feature_T  %%[due:: 2012-04-30]%%
- [x] 2012-02-20 add this feature_U  %%[completion:: 2012-02-21]%%



  • filename : dic_20120301
---
Date: 2012-03-01
---
## input
### input_m:  milestones
- 2012-03-01 Started learning Javascript  #Test/d01 [[Note J]] , [[Note K]]
- 2012-03-02 Wrote a "Hello world" script, and it worked! #Test/d02 [[Note J]]
- 2012-03-03 Learned how to fetch data from a URL #Test/d03
- 2012-03-04 Learned about Promises #Test/d04
- 2012-03-05 Learned about await/async #Test/d05[[Note K]]
- 2012-03-06 Started working with NPM libraries #Test/d06
- 2012-03-07 Published my first code to Github #Test/d07
- 2012-03-08 Published my first code to Github


### input_t: tasks
- [ ] 2012-03-11 add this feature_A  #Test/d01 [[Note P]] , [[Note Q]]
- [ ] 2012-03-12 add this feature_B #Test/d02  [[Note P]]
- [ ] 2012-03-13 add this feature_C #Test/d03
- [x] 2012-03-14 add this feature_D #Test/d04
- [ ] 2012-03-15 add this feature_E #Test/d05 [[Note Q]]
- [x] 2012-03-16 add this feature_F #Test/d06
- [x] 2012-03-17 add this feature_G #Test/d07
- [ ] 2012-03-18 add this feature_S  %%[created:: 2012-03-18]%%
- [ ] 2012-03-19 add this feature_T  %%[due:: 2012-05-30]%%
- [x] 2012-03-20 add this feature_U  %%[completion:: 2012-03-30]%%




DQL50_flatten_fLists_groupBy_tags_and_count_tasks_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL50_flatten_fLists_groupBy
_tags_and_count_tasks_and_LIST
tasks with tags/outlinks or not yes To count tasks with tags where tasks are not done 1.To fiter by tasks
2.To fiter by uncompleted tasks
3.To filter by L.tags
4.To groupBy L.tags
5.To dispay it as a list

Code DQL50_flatten_fLists_groupBy_tags_and_count_tasks_and_LIST

Summary_code
title: DQL50_flatten_fLists_groupBy_tags_and_count_tasks_and_LIST =>1.To fiter by tasks 2.To fiter by uncompleted tasks 3.To filter by L.tags 4.To groupBy L.tags 5.To dispay it as a list
collapse: close
icon: 
color: 
```dataview
LIST WITHOUT ID
      "Open tasks that include " + GF_L_tags + ": " + length(rows.F_event)
FROM "100_Project/02_dataview/Q11_Tasks/Q11_test_data"

FLATTEN file.lists AS L
WHERE L.task and !L.completed
WHERE L.tags
GROUP BY L.tags AS GF_L_tags

```

Screenshots(DQL50)


This is great, can you post the code for the Total: 150 too? Thanks!

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