Task query with multiple tags with inconsistent order that will put them in the same group

What I’m trying to do

I’m trying to write a query that groups tasks with multiple tags into the same group regardless of the order of the tags written as long as the combination of the tags is the same.

Just as the background information, I use tags to organize my tasks. I use one main tag that identifies the type of task, but also use other tags to indicate whether if it’s something I like to work on today, this week or later or any other information that I would like to note as a tag.

Things I have tried

To achieve what I’m trying to do, I wrote a query that shows a list of tasks with multiple tags by using the task.tags.join command. The problem that I’m having is that I write tags in inconsistent order which is creating multiple groups that essentially has the same combination of tags.

My query is something like below:

not done
tag includes Work
group by function task.tags.join(" & ")

When I execute this query, it would have groups like

#Work & #Today”, but there will be another group named
#Today & #Work” depending on the order of the tags I wrote in the tasks.

Is there a solution to resolve this problem?

Not sure whether you actually can do this in Tasks, but the solution to your issue is to sort the tags, before you use them to join and group by.

Hey Holroy,

Thank you for the input! Could you elaborate on what you meant by you are not sure if this can be done in Tasks? Is there a way to sort the tags in other methods?

I’m trying to allow people to use the task engine they want, so when you asked using a tasks query I responded in that context.

I do believe the following might do what you want:

```dataview
TASK FROM #Work
WHERE !completed
GROUP BY join(sort(tags), " & ")
```

Thank you holroy!
Your dataview query achieved what I wanted to do. I didn’t know how to use dataview until now, but this definitely will get me going :slight_smile:

But I still have one issue. Your query returns the tasks that I want to show specified with the FROM command, but it also shows other tasks that do not have the tag.
I can’t seem to find a pattern or reason for the tasks that are erroneously showing up.
Do you have any idea why this would be the case?

I actually was able to resolve the problem by using the contains command instead of from.

so query I used was:

```dataview
TASK
WHERE !completed AND contains(tags, "#Work")
GROUP BY join(sort(tags), " & ")

Thank you so much holroy!