Excluding a tag from a list of tags grouped by tag (see text and example)

I think the following screenshot shows what I’m trying to achieve, and I’m mostly there:

Here’s the query that does this:

```dataview
TABLE WITHOUT ID tag AS "Tag", (rows.file.link) AS "Notes", join(rows.file.etags, "<br>") as "Tags"
FLATTEN file.etags AS tag
GROUP BY tag
SORT file.ctime DESC
```

What I’m hoping for help with: Since I’m already grouping by tag (left column), how can i remove that tag from the list of the other tags (right column) that are contained in each file (middle column). In other words, I want the screen-shot but without the tags marked with the hand-drawn red “x”s, since each is already on the right side for the respective row.

I believe the answer is in the join statement, where in rows.file.etags I need to exclude the tag for that entry. But I’m not sure how to write this.

Any ideas? Many thanks in advance!

Use the regexreplace function.(DQL10)

Topic

Summary
  • How to exclude the tag(key) (left column) from the tags (right column) for that entry?

Test

Summary
  • dataview: v0.5.55

Input

Summary

dictionary files:

  • Location: “100_Project/02_dataview/Q74_GroupBy_etag/Q74_test_data”

folder: 03

  • filename : dic_19640301
  • filen.ctime: “1964-03-01T19:30:50”
---
Date: 1964-03-01
---
#T03
#T04
#T05


folder: 04

  • filename : dic_19640401
  • filen.ctime: “1964-04-01T19:30:50”
---
Date: 1964-04-01
---
#T03
#T04
#T05


folder: 05

  • filename : dic_19640501
  • filen.ctime: “1964-05-01T19:30:50”
---
Date: 1964-05-01
---
#T03
#T04
#T05


DQL01_FLATTEN_etags_groupBy_etag_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL01
_FLATTEN_etags
_groupBy_etag
_and_TABLE
file.etags:
an array of strings like [“#T03”, “#T04”, “#T05”]
yes 1.To filter by file.etags

2.To sort by file.ctime in descending order

3.To FLATTEN file.etags AS etag:
3.1 To break up a list like file.etags in a file into each individual element in a file
3.2 To define a field variable etag as each element of file.etags of each page

4.To group by etag

5.To define a field variable etags_joined

6.To display the result as a table

Code DQL01_FLATTEN_etags_groupBy_etag_and_TABLE

Summary_code
title: DQL01_FLATTEN_etags_groupBy_etag_and_TABLE =>1.To filter by `file.etags` 2.To sort by `file.ctime` in descending order 3.To FLATTEN file.etags AS etag: 3.1 To break up a list like `file.etags` in a file into each individual element in a file 3.2 To define a field variable `etag` as each element of `file.etags` of each page 4.To group by `etag` 5.To define a field variable `etags_joined` 6.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      key AS "Tag(key)", 
      rows.file.link AS "Notes", 
      etags_joined as "Tags"

FROM "100_Project/02_dataview/Q74_GroupBy_etag/Q74_test_data"

WHERE file.etags
SORT file.ctime DESC

FLATTEN file.etags AS etag

GROUP BY etag AS G_etag

FLATTEN "• " + join(rows.file.etags, "<br>• ") AS etags_joined
```

Screenshots(DQL01)


DQL03_GroupBy_etag_and_Remove_key_from_etags_joined_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL03
_GroupBy_etag
_and_Remove_key
_from_etags_joined
_and_TABLE
file.etags:
an array of strings like [“#T03”, “#T04”, “#T05”]
yes 1.To filter by file.etags

2.To sort by file.ctime in descending order

3.To FLATTEN file.etags AS etag:
3.1 To break up a list like file.etags in a file into each individual element in a file
3.2 To define a field variable etag as each element of file.etags of each page

4.To group by etag

5.To define a field variable etags_joined

6.To remove the key from the etags_joined

7.To display the result as a table
1.The DQL03 is based on the DQL01.
1.1 Purposes 6 is added.

Code DQL03_GroupBy_etag_and_Remove_key_from_etags_joined_and_TABLE

Summary_code
title: DQL03_GroupBy_etag_and_Remove_key_from_etags_joined_and_TABLE =>1.To filter by `file.etags` 2.To sort by `file.ctime` in descending order 3.To FLATTEN file.etags AS etag: 3.1 To break up a list like `file.etags` in a file into each individual element in a file 3.2 To define a field variable `etag` as each element of `file.etags` of each page 4.To group by `etag` 5.To define a field variable `etags_joined` 6.To remove the `key` from the `etags_joined` 7.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      key AS "Tag(key)",  
      rows.file.link AS "Notes",
      etags_excluding_key as "Tags"

FROM "100_Project/02_dataview/Q74_GroupBy_etag/Q74_test_data"

WHERE file.etags
SORT file.ctime DESC

FLATTEN file.etags AS etag

GROUP BY etag AS G_etag


FLATTEN "• " + join(rows.file.etags, "<br>• ") AS etags_joined


FLATTEN regexreplace(etags_joined, key, "") AS etags_excluding_key
```

Screenshots(DQL03)


DQL10_GroupBy_etag_and_Remove_key_and_unnecessary_comma_from_etags_joined_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_GroupBy_etag
_and_Remove_key
_and_unnecessary_comma
_from_etags_joined
_and_TABLE
file.etags:
an array of strings like [“#T03”, “#T04”, “#T05”]
yes 1.To filter by file.etags

2.To sort by file.ctime in descending order

3.To FLATTEN file.etags AS etag:
3.1 To break up a list like file.etags in a file into each individual element in a file
3.2 To define a field variable etag as each element of file.etags of each page

4.To group by etag

5.To define a field variable etags_joined

6.To remove the key and unnecessary comma from the etags_joined

7.To display the result as a table
1.The DQL10 is based on the DQL03.
1.1 Purposes 6 is modified.

Code DQL10_GroupBy_etag_and_Remove_key_and_unnecessary_comma_from_etags_joined_and_TABLE

Summary_code
title: DQL10_GroupBy_etag_and_Remove_key_and_unnecessary_comma_from_etags_joined_and_TABLE =>1.To filter by `file.etags` 2.To sort by `file.ctime` in descending order 3.To FLATTEN file.etags AS etag: 3.1 To break up a list like `file.etags` in a file into each individual element in a file 3.2 To define a field variable `etag` as each element of `file.etags` of each page 4.To group by `etag` 5.To define a field variable `etags_joined` 6.To remove the `key` and unnecessary comma from the `etags_joined` 7.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      key AS "Tag(key)",  
      rows.file.link AS "Notes",
      etags_excluding_key_and_comma as "Tags"

FROM "100_Project/02_dataview/Q74_GroupBy_etag/Q74_test_data"

WHERE file.etags
SORT file.ctime DESC

FLATTEN file.etags AS etag

GROUP BY etag AS G_etag


FLATTEN "• " + join(rows.file.etags, "<br>• ") AS etags_joined


FLATTEN regexreplace(etags_joined, key + ",*|, " + key , "") AS etags_excluding_key_and_comma
```

Screenshots(DQL10)


Reference

Summary

Emojis

The groupBy, groupIn and Data structures

  • Q16_GroupIn: The DVJS10_Q1, The DVJS20_Q1 from Solutions

One way to do this is to filter out the unwanted element, doing something like:

join(filter(rows.file.etags, (t) => t != tag)), ", ") as "Tags"

I’m trying to do a similar thing. I want to see the files with a tag of #project and then display the other tags associated with the file.

Here’s the query I’ve got now based on input from @holroy


TABLE 
file.tags AS "Tag",
filter(rows.file.tags, (t) => t != "project") as "Tags",
file.mtime AS "Last Touched"
FROM #project


As you can see, the result in the tags field is blank rather than just showing the tags other than #project.

I would appreciate any help you can give.

Try changing just this part to filter(file.tags and leave everything else as is. You’re not grouping stuff, so you don’t need the rows.

Brilliant! Thank you very much.

Thanks @holroy for your reply (and sorry for the delay; damn forum not notifying me!).

Unfortunately that didn’t work. I’ve been playing a bit but no dice. I’m at a bit of a loss. Here’s where the query is at:

```dataview 
TABLE WITHOUT ID tag AS "Tag", (rows.file.link) AS "Notes", join(filter(rows.file.tags, (t) => t != tag), "<br>") as "Tags" 
FLATTEN file.tags AS tag 
GROUP BY tag 
SORT file.ctime DESC 
```

The query itself works fine. It just doesn’t remove the current tag (from “Tag”) in the list of all tags (in “Tags”) for each note.

EDIT: In fact, even if I hard-wire one of my tags in, it still doesn’t filter it out. E.g.

join(filter(rows.file.tags, (t) => t != "#active-gals")

Weirdly, even if I try and reproduce @cobbenterprises 's query above, not even that works! Ug!

```dataview
TABLE 
file.tags AS "Tag", 
filter(file.tags, (t) => t != "active-gals") as "Tags", 
file.mtime AS "Last Touched" 
FROM #active-gals
```

I get a nice table with tags and all. Just the tag I’m trying to exclude is still there in the full tag (for the note) list. :frowning: