Dataview Task Group By Heading and Subheading

What I’m trying to do

Hello, I am trying to create a dataview task list with header and sub-header hierarchy. In the dataview, I would like the date (e.g., November 21, 2023) as the heading and the meeting title (e.g., Meeting A) as the sub-heading.

Here is the task list format:

November 21, 2023

Meeting A

  • Task 1A

Meeting B

  • Task 1B
  • Task 2B
  • Task 3B

Meeting C

  • Task 1C
  • Task 2C
  • Task 3C

November 22, 2023

Meeting A

  • Task 1A

Meeting B

  • Task 1B
  • Task 2B
  • Task 3B

Meeting C

  • Task 1C
  • Task 2C
  • Task 3C

November 23, 2023

Meeting A

  • Task 1A

Meeting B

  • Task 1B
  • Task 2B
  • Task 3B

Meeting C

  • Task 1C
  • Task 2C
  • Task 3C

Things I have tried

I have tried GROUP BY by header and GROUP BY meta(section).subpath but it does not provide the heading and subheading hierarchy.

For example,

TASK
FROM "Tasks"
GROUP BY header

And the other example,

TASK
FROM "Tasks"
GROUP BY meta(section).subpath

I think what you are trying to do is not possible. If you look at the doco, the first part of the task description says,

The TASK Query outputs an interactive list of all tasks in your vault that match the given data commands (if any). TASK queries are special compared to the other Query Types because they do give back Tasks as results and not pages . This implies that all data commands operate on Task level and makes it possible to granularly filter your tasks i.e. for their status or meta data specified on the task itself.

I think that bit about it being different to the other dataview types because it gives back tasks instead of pages, means that you are doomed.

I have been avoiding DataviewJS, but find myself in a situation like you quite regularly now, where I just want to wrap something in a for/while loop… So perhaps that is the answer… then you can loop by day in js, and then just use the DV object for tasks per day.

Using basic queries, you only get one level of grouping. Using a pure dataviewjs you can get two level of queries (at least for more generic queries), using a “group in” function. You can also combine the two in two variants.

You could either use a standard query and group on the combination of the day and meeting. It’ll be one level of headings, but you’ll get the tasks in their proper groups.

Or you could use a standard query called from dataviewjs, and manipulate the output. (This is if you don’t want to or can’t use the dual grouping it’s offering)

1 Like

Thanks for the inputs @PeterInBrisbane and @holroy!

Any idea on how to do this with dataviewjs?

I figured out how to list all the tasks in the file “Tasks” with the dataviewjs code (below). However, I am struggling how to incorporate the group by function with headings documented here: Grouping - Tasks User Guide - Obsidian Publish

Any ideas?

group by function (task.heading + ‘.md’ === task.file.filename) ? ‘’ : task.heading

dv.taskList(dv.pages(-"Tasks").file.tasks)

Here is the source code for Tasks.md

## November 21, 2023

### Meeting A
- [ ] Task 1A

### Meeting B
- [ ] Task 1B
- [ ] Task 2B
- [ ] Task 3B

### Meeting C
- [ ] Task 1C
- [ ] Task 2C
- [ ] Task 3C


## November 22, 2023

### Meeting A
- [ ] Task 1A

### Meeting B
- [ ] Task 1B
- [ ] Task 2B
- [ ] Task 3B

### Meeting C
- [ ] Task 1C
- [ ] Task 2C
- [ ] Task 3C

## November 23, 2023

### Meeting A
- [ ] Task 1A

### Meeting B
- [ ] Task 1B
- [ ] Task 2B
- [ ] Task 3B

### Meeting C
- [ ] Task 1C
- [ ] Task 2C
- [ ] Task 3C

You’re mixing stuff from two plugins here. The “group by heading” is related to the Tasks plugin, but the other advice has so far focused on the dataview plugin. They’re two different beasts…

1 Like

@holroy you’re right! Thanks for pointing this out.

I am open to any plug-in or method to achieve the end result I mentioned above.

I tried this group by function with the tasks plug-in but received this error message. Any ideas?

tasks
group by function (task.heading + '.md' === task.file.filename) ? '' : task.heading"

1 Like

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