Group by subtags with dataview

What I’m trying to do

I want to create a table of my projects grouped by status (idea, running, finished,…).
I use subtags to define the status of the projects, so its #project and #status/running in the top section of the note.
The table should be defined like:
TABLE name.link
FROM #Project
GROUP by #Status/
and then all projects are gouped by there current status.
Is this possible?

I know I could define a new dataview variable “status” and group by it, but I use the tag system a lot and want to be able to use the obsidian search tag option.

Things I have tried

Using GROUP by tag I get all tags. :x:
Using GROUP by #status, I get an error that “#” is not valid :x:
Using Group by tag (’#Status/’) I get an error that “(” is not valid :x:

Thanks :slight_smile:

@FriSti


dataview
table WITHOUT ID
FROM #projects
GROUP BY status


If that doesn’t help, maybe explaining from Dataview documentation will aid you -

the GROUP by function is simply written as

GROUP BY field or in your case GROUP BY status

it might be the only way you haven’t tried, I did the exact thing :crazy_face:

Hi.

1 - to get only the exact tags (and not “nested tags + parent tags”), use file.etags instead of file.tags;

2 - to separate groups of tags (because in each file you have multiple tags), you need to flatten them >>> FLATTEN file.etags AS Tags (“Tags” is the new name to the new list of tags);

3 - after FLATTEN, you need to exclude all the unwanted tags (for example, #project), in the case using the filter WHERE contains(Tags, "#status/") (only tags with “#status/”);

4 - now, finally, you can group them:

```dataview
TABLE WITHOUT ID Tags AS "Status", rows.file.link AS "Files"
FROM #Project
FLATTEN file.etags AS Tags
WHERE contains(Tags, "#status/")
GROUP BY Tags
SORT Tags DESC
```

5 - I deduce you want to sort status tags not alphabetically but in the order “idea” > “running” > “finished”. You can’t achieve this sorting tags using only “ASC” or “DESC”. You need to create your wanted order. I give you an option with a “constructed” order:

```dataview
TABLE WITHOUT ID Tags AS "Status", rows.file.link AS "Files"
FROM #Project
FLATTEN file.etags AS Tags
WHERE contains(Tags, "#status/")
GROUP BY Tags
SORT choice(contains(Tags, "idea"), "1", choice(contains(Tags, "running"), "2", choice(contains(Tags, "finished"), "3", "4"))) ASC
```
3 Likes

I totally forgot to answer!
Thank You a lot, this has solved my problem (by I still have to really understand the syntax :wink: )

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