Grouping tasks with subtasks by tags

Hello Dear Obsidian Community!

As a noob in this community, I would greatly appreciate your help in my small problem.

What I’m trying to do

I am trying to group my tasks with subtasks by their tags from a page. The tags are added in the parent task only.

Things I have tried

I have tried the following,

TASK
WHERE icontains(file.name,this.file.name)
GROUP BY tags

This groups the task with subtasks by their tags. However, the subtasks without tags are grouped with the parent tasks that are without tags. This is not what I want. I want the subtasks to be only under their parent task.

Forgive me for my english. I am not a native speaker.

Thank you!

In general both the TASK and LIST queries against file.lists kind of ignores the level of the task/list item for most parts. You can in some cases see subtasks, but it’s kind of hard to achieve what you’re looking for.

You could possibly get what you’re looking for doing something like:

```dataview
TASK
WHERE icontains(file.name, this.file.name)
  AND length(children) > 0
GROUP BY tags
```

This adds a requirement that the task you want to show needs to have subtasks. Then again, this might remove those tasks not having any subtasks. Alternatively you could possibly play around with the parent field to check that your task doesn’t have a parent, and are at the row level.

See metadata on tasks and lists for more information on what extra fields are available for playing around in such a query. Maybe the following suits your needs?


```dataview
TASK
WHERE file = this.file
  AND !parent
GROUP BY flat(list(tags))[0] as Tags
```

In my test setup this outputs this:
image

2 Likes

Hello!

Thank you for your support. I tried your last query. Unfortunately it is giving me error.
image

Any idea what this might be?

Thanks!

I think you might need to update your dataview plugin. It’s a relatively new function, but it should be in there if your plugin is updated.

Thank you for your magic. It worked beautifully!!

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