Dataview group first by topic-tag

Hi there, I think, it’s just the correct syntax I need.
I have this dataview table:

---
author: Klein, Dieter
title: "}b Klein D. Zukunft oder Ende des Kapitalismus"
subtitle: Eine kritische Diskursanalyse in turbulenten Zeiten
aliases: 
parent: "[[Index Literatur]]"
prio: 5
frist: xx-xx-xx
tags:
  - literatur/todo
  - Wachstum
  - Kapitalismus
  - Klimakrise
topic: "#Klimakrise"
---
  1. I’d like to use the already existing tags (#Hashtags) in my vault as values for the variable “topics” to choose them so easy as for the variable “tags”.

  2. I’d like to group and sort by the hashtag in “topic” to have all entries of one topic area together.

Apreciate all hints :slight_smile:

Okay. Let me summarize in points.

  1. That is not a DataView table; it’s a frontmatter AKA YAML block.

  2. I’d advise using just tags or topic property values to be put in the frontmatter to remove these kind of duplicates.

  • Our friend @holroy (not wanting to ping him but his remarks on all matters need to be checked; people should use the forum search more and be less reliant on his time) also advises on using dedicated status or topic properties, as we talked about this on this thread as well.
  1. To do the job of getting rid of some of the tags and converting them to topic property values (if one doesn’t want to do this by hand) is not that easy but in the link given we’ve covered some of the bases.

So based on what you want to do (first; should you want to do the first at all), you’d need two DV queries.

  1. To do the conversion you’ll need to query for tags.
```dataview
TABLE
FROM ""
WHERE econtains(flat(list(file.tags)), "#Klimakrise")
SORT file ASC
```
  1. Then do the query you want (your ultimate, most immediate request).
    Something like this:
```dataview
TABLE
FROM ""
WHERE econtains(topic, "Klimakrise")
SORT file ASC
```

Or possibly better:

```dataview
TABLE
FROM ""
WHERE econtains(flat(list(topic)), "Klimakrise")
SORT file ASC
```

If you have way more in the way of tags and don’t want to do conversions (you’ll need tools for that and some time), use the first one. Possibly try out all three.

1 Like

If when defining the topic field you want to select from all of the currently available tags, you’d need to use a plugin like metadata menu, and setup a topic field definition which uses a select type with a query to list all the tags of your vault.

Further note that a topic defined as you’ve done, using topic: "#Klimakrise" is not recognised by Obsidian as a use of that tag, so to tag this file with that tag you’d also need it included in the tags section like you’ve done in your example already.

Based on the previous it could be argued that you should rather have the topic field be just: topic: Klimakrise so as not to confuse it with a tag declaration.

If you want to make a Dataview query to list all entries related to the various topics you could try with something like the following:

```dataview
LIST rows.file.link
WHERE topic
GROUP BY topic
```

That should list all files having a topic, and group them together by that topic.