Dataview Table - Display ALL files on a Project folder AND a colum with tasks with a certain tag

What I’m trying to do

I have a “Project” folder with all the projects I’m working on.
Inside each project file, I have tasks pertinent to each project.

I want a table showing ALL the files in the “Project” folder and a second column called “NextAction,” with the task text of those tasks flagged with a #nextaction tag attached.

If any particular project file has no tasks or none of the tasks listed on the project file have a #nextaction tag, leave the column empty but still show the project name.

One of the bases of GTD is ensuring every project has a Next Action. This will make it easy to achieve it.

Things I have tried

I tried the following TASK query, but I would like to achieve something similar with a TABLE query so I can get ALL the files regardless of whether they have tasks or not:

TASK 
FROM "Projects" 
WHERE !completed AND -#nextaction
GROUP BY file.link

Please help

1 Like

You can use a Dataview table and list all files from the “Project” folder. There you can include a column for tasks with the #nextaction tag . If there’s no task with #nextaction, leave the task column empty but still show the file. Here is code that you can use for fix the issue:

```dataview
TABLE file.name AS "Project", task.text AS "NextAction"
FROM "Projects"
FLATTEN file.tasks as task
WHERE contains(task.text, "#nextaction") OR !contains(file.name, " ")
GROUP BY file.name

I hope my suggestion will be helpful for everyone.

Did you try this query, @JamieC1 ? I suspect it doesn’t work since after you’ve used GROUP BY all the fields will be grouped into the rows object. So task.text, would become the list rows.task.text, and so on.

Furthermore, using a TABLE query instead of a TASK query, changes the output from being actionable tasks (with link backs to the origin of the task itself) , to just readonly task descriptions. This do work in some cases, and I do see that’s what the OP asks for, but it’s a different list altogether and I wanted to point out this difference.

As previously mentioned if you want to use a table, you’ll loose the task capabilities. With that sorted out, we can proceed to ask a question on how do yo want to treat files not having tasks at all, or only completed tasks? Should they show up in your table?

Assuming you only want to list files having some uncompleted tasks, either they’re marked with #nextaction or not, then something like the following query could be a starting point:

```dataview
TABLE none( map(nonCompletedTasks, (task) => contains(task.tags, "#nextaction"))) as "Has no next task", nonCompletedTasks.text as "All non-completed tasks"
FROM "Projects"
FLATTEN list(filter(file.tasks, (task) => !task.completed)) as nonCompletedTasks
```

A variation of the same query could be:

```dataview
TABLE NoNext, nonCompletedTasks.text as "All non-completed tasks"
FROM "Projects"
FLATTEN list(filter(file.tasks, (task) => !task.completed)) as nonCompletedTasks
FLATTEN choice(none( map(nonCompletedTasks, (task) => contains(task.tags, "#nextaction"))),
"No next task",
"") as NoNext
```

or possibly this list variant:

```dataview
LIST toComplete
FROM "Projects"
FLATTEN list(filter(file.tasks, (task) => !task.completed)) as nonCompletedTasks
FLATTEN choice(none( map(nonCompletedTasks, (task) => contains(task.tags, "#task"))),
"No next task, ",
"") + " (" + length(nonCompletedTasks) + ")" as toComplete
```

Output of the latter two variants from my test vault (with slightly difference in tag choices):

image

Here the number indicates how many tasks are left to complete.

1 Like

Thank you very much @JamieC1 !
Unfortunatelly it doesn’t render all the Projects. I tried to make it work with no success.

Wow @holroy ! This is EXACTLY what I was looking for! :raised_hands: :pray:
What a clever way to use the FLATTEN command! I didn’t know you could filter at the same time.

Quick question, and not because your solution is not perfect, but just out of curiosity to learn other uses of the FLATTEN command.

How do you filter the last column to show ONLY tasks with the #nextaction tag instead of all uncompleted tasks?

1 Like

You could either extend the nonCompletedTasks thingy, or do a separate one like in:

FLATTEN list(filter(file.tasks, (task) => !task.completed AND contains(task.tags, "#nextaction"))) as nextTasks

Then you could add nextTasks.text as a column in your query like I did for the nonCompletedTasks.text column.

1 Like

Super! Thank you very much :slight_smile:

1 Like

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