Displaying count of tags for specific notes

I have a database that contains stories written by authors. Each note has a bunch of YAML tags that look like this:

---
author: "Arthur"
words: 3579
date: 2024-12-15
type: "long story"
---
---
author: "Arthur"
words: 231
date: 2024-12-17
type: "short story"
---
---
author: "Bob"
words: 152
date: 2024-12-16
type: "short story"
---

What I’m trying to do

My goal is to use Dataview to have a monthly summary of activity of each of the authors. My ideal table would look like this:

Author Words Long stories Short stories
Arthur 3810 1 1
Bob 152 0 1

Things I have tried

I didn’t have a problem summing the number of words and aggregating them by author, but after I added the column “Long stories” the table stopped counting all the words that were written by a particular author, only for the long stories. And I can’t add any more columns. Is there a way to make Dataview calculate all the words written and then simply give a number of particular types of stories written by a certain author?

```dataview
TABLE WITHOUT ID 
Author, 
sum(rows.words) as "Words", 
length(rows.Type) as "Long stories" WHERE Typ = "long story"
WHERE date >= date("2024-12-01") and date <= date("2024-12-31")
WHERE author != null
GROUP BY author
SORT author ASC

To get the goal you want, you need to get the length of the filtered list of rows matching your criteria. The following query should do that, if I’ve not done some stupid mistake. :slight_smile:

```dataview
TABLE WITHOUT ID 
Author, 
sum(rows.words) as "Words", 
LongCount as "Long stories",
ShortCount as "Short stories"
WHERE date >= date("2024-12-01") and date <= date("2024-12-31")
WHERE author != null
GROUP BY author
FLATTEN length(filter(rows.type, 
  (type) => type = "long story")) as LongCount
FLATTEN length(filter(rows.type,
  (type) => type = "short story")) as ShortCount
SORT author ASC
```
1 Like

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