Dataview - in a TASK query, how do I GROUP BY multiple fields?

What I want

I want a dataview task query that returns tasks grouped by due date then within each date grouped by section. The tasks live on pages that have sections related to different opportunities.

I expect the result would look something like this:

January 1, 2022
Opportunity 1
- task one
- task two
Opportunity 2
- task one
- task two

January 2, 2022
Opportunity 1
- task one
- task two
Opportunity 2
- task one
- task two

What I’ve tried that has not worked

TASK
FROM "myfolder"
WHERE !completed
GROUP BY due AND section

Also

TASK
FROM "myfolder"
WHERE !completed
GROUP BY due
GROUP BY section

What I’ve tried that returns a result but not what I want

TASK
FROM "myfolder"
WHERE !completed
GROUP BY due
TASK
FROM "myfolder"
WHERE !completed
GROUP BY section

Thank you for any help!

3 Likes

hmm, working with multiple groups in Tasks queries is definitely a hard “task” :slight_smile: (at least in dql… but I don’t know js).

I can suggest a way, not exactly as your desired output, but “similar”.

The idea is: joining both fields and group them.

Try both examples:

1

TASK
FROM "myfolder"
WHERE !completed
GROUP BY list(due, section) AS abc

2

TASK
FROM "myfolder"
WHERE !completed
GROUP BY (due + "<br>" + section) AS abc
4 Likes

Thanks!

It appears that option 1 sorts alphabetically by Month name, so I am assuming that method is converting the date to text. Option 2 allows me to continue to sort by date, so I am doing this for now. Thank you so much!

TASK
FROM "myfolder"
WHERE !completed
GROUP BY list(due, section) AS ToDo
SORT ToDo DESC

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