How to display only last subtag in Dataview

In Dataview table, I only want to display the last subtag (for example ‘Graphic’). However, when using file.etags, the full tag (e.g. ‘Software/Graphic’) is shown instead. How can I extract and display only the last subtag?

My code:
image
What’s displayed:
image

The following displays just Graphic. What you want?

---
tags: Software/Graphic
---

```dataview
TABLE 
string(map(file.etags, (t) => split(t, "/")[length(split(t, "/")) - 1])) AS Tags
FROM #Software/Graphic
```

Reference: Dataview : display a subtag only? (Also discussed : Sort/Group by subtag) - #4 by mnvwvnm

There has been some addition to dataview making this a little nicer: map(file.etags, (t) => slice(split(t, "/"), -1) This would pick the last part of any nested tag within file.etags.

Thank you for your amazing solution! I do have a small issue, though. When a tag is not nested and consists of only one word, Dataview displays it with a # at the beginning. Is there a way to remove the # while keeping the code clean? Thanks again!
image
image

1 Like

So you don’t want the hash tag… Then you could do replace(t, "#", "") or substring(t, 1) instead of the t inside of split. Or you could do a regexreplace on the entire string, maybe something like regexreplace(t, "#.*\/?(.*)", "$1") instead of the slice and split combo.

All of these are untested, and written in the dark of the night, so if they’re not working I’ll do better tomorrow.

1 Like

Hi.

The code suggested by @holroy works in a local test file:

---
tags: 
  - Software/Graphic
---

#Obsidian #Books


```dataview
TABLE 
string(map(file.etags, (t) => split(replace(t, "#", ""), "/")[length(split(t, "/")) - 1])) AS Tags
WHERE file.name = this.file.name
```

Here is a complete working example with all three variants on removing the # and splitting the remaining and only listing the last part of a nested tag.

```dataview
TABLE
  join(map(file.etags, (t) => regexreplace(t, "#(?:.*\/)?(.*)", "$1"))) as regexreplace,
  join(map(file.etags, (t) => slice(split(replace(t, "#", ""), "/"), -1))) as sliceSplitReplace,
  join(map(file.etags, (t) => slice(split(substring(t, 1), "/"), -1))) as sliceSplitSubstring
WHERE file = this.file
```

Based on the example file provided by @Guapa , this gives:

Which one to use? I’d say, use the one which makes the most sense to you, and you possibly could recreate on your own in a similar case later on.