Dataview: filter for nested tags not empty

What I’m trying to do

I am trying to create a dataview query for files that have a certain nested YAML tag not empty. Unfortunately, there seems to be a problem filtering for the specific sub-tag.

For example, this is the frontmatter of file A:

- categoryA: 1

And this is the frontmatter of file B:

- categoryB: 1

Now I would like to filter for all files that have some value in index.categoryA
I use this query:

TABLE index.categoryA
WHERE index.categoryA
sort index.categoryA asc

Instead of only displaying file A, dataview displays both file A and B. What am I missing?
Screenshot 2023-03-21 174114

This was strange indeed, and I’m border line tempted to call this a bug within dataview.

I tried some variant using row["index"]["categoryA"] but that behaved the same, so then I thought about using FLATTEN, and that seems to do the trick. Not sure if it’ll have some side effects or not in a larger scenario, but for this simple query this seems to do the trick:

FLATTEN index.categoryA as catA
SORT catA asc
Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

1 Like

Hey, thank you for responding.
Your solution seems to work quite nicely!
I also implemented it in the actual project I was working with, which includes many more files and more complicated tag nesting. I am pretty sure this counts as a bug, but as for now, this is more than good enough!

1 Like

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