Hide empty dataview queries

I have a very complicated Gratitude Journal set up. I have 22 very broad categories in a list to help me think of topics to be grateful for.

In my daily Journal there is a list like bellow but shortened.

  • #Gratitude-Parents

    • Note goes here
  • #Gratitude-Grandparents

    • Note goes here
  • #Gratitude-Immediate-Family

    • Note goes here

Then in my monthly review I have 22 dataview queries that searches my daily journal for these tags and combines themtogether. Here is the query I have right now.

TABLE WITHOUT ID C.text as "Parents"
From "Test_Plugins/Daylie notes/2022/09_Sep"
FLATTEN file.lists as L
WHERE join(L.tags, "") = "#Gratitude-Parents"
FLATTEN L.children as C

Here is the problem. I am not always going to fill every topic and with 22 having a bunch of empty tables laying around cluters things up.

I was reading around the form and found this query by @AlanG. When I put a bunch of his queries in my notes it collapses exactly how I would like mine to.

I just don’t know how to convert my query to a js query or make mine show nothing when there is zero lists to show.

const notes = dv.pages('#this-week')
if (notes.length) dv.list(notes.file.link)

Is this possible with normal Dataview queries?

With a DQL no. But you can use a tricky way in dataviewjs: using your DQL inside DVJS.

Try this way:

// place your query here
const query = `TABLE WITHOUT ID C.text as "Parents"
From "Test_Plugins/Daylie notes/2022/09_Sep"
FLATTEN file.lists as L
WHERE join(L.tags, "") = "#Gratitude-Parents"
FLATTEN L.children as C`

// executing the dataview query and return results
let DQL = await dv.tryQuery(query);

// render the table only if any value
if (DQL.values.length > 0){
	dv.table(DQL.headers, DQL.values)
}

question: what’s the reason to join(L.tags, "") = "#Gratitude-Parents" and not only contains(L.tags, "#Gratitude-Parents")?

2 Likes

Thank you very much @mnvwvnm

Answer: Copy pasta from the internet without understanding dataview/js or thinking about what it.

@mnvwvnm Any idea these two queries is collecting the same content? For some reason my prayer requests are showing up in my all of my different gratitude lists which are all pointing to different #tags. I just put a note under the #Gratitude-Sugnificant-other and it is appearing under #gratitude-Parents, #gratitude-Job-And, #Gratitude-Education, etc. Maybe I have too many dataivews in this note? It was working the other day and still is in my test note.

const query = `TABLE WITHOUT ID C.text as "Prayer Request"
FROM "Journal/2022/10_Oct"
FLATTEN file.lists as L
WHERE join(L.tags, "") = "#Prayer-Request"
FLATTEN L.children as C`

// executing the dataview query and return results
let DQL = await dv.tryQuery(query);

// render the table only if any value
if (DQL.values.length > 0){
	dv.table(DQL.headers, DQL.values)
}
const query = `TABLE WITHOUT ID C.text as "Society"
FROM "Journal/2022/10_Oct"
FLATTEN file.lists as L
WHERE join(L.tags, "#Gratitud-Society")
FLATTEN L.children as C`

// executing the dataview query and return results
let DQL = await dv.tryQuery(query);

// render the table only if any value
if (DQL.values.length > 0){
	dv.table(DQL.headers, DQL.values)
}

I can’t guess without the raw content…
But looking only to the queries, there’s something wrong…
What’s this WHERE join(L.tags, "#Gratitud-Society")?

Sorry, I realized way later that I gave no context.

In Daily Note

In my daily note I have 23 lists with #Tags as their first level list, each day when I have a prayer request or gratitude I create a second level note.

- #Tag1
  - Note

- #Tag2
  - Note

- #Tag3
  - Note

In Monthly Note

This Querry is repeated 23 times replacing TagX with whatever tag above I am trying to target. What This query does in my test notes is look at all this months daily notes and collect all the sub notes from under the #Tag it targets.

const query = `TABLE WITHOUT ID C.text as "Tag X"
FROM "Journal/2022/10_Oct"
FLATTEN file.lists as L
WHERE join(L.tags, "") = "#TagX"
FLATTEN L.children as C`

// executing the dataview query and return results
let DQL = await dv.tryQuery(query);

// render the table only if any value
if (DQL.values.length > 0){
	dv.table(DQL.headers, DQL.values)
}

In practice

The Problem I have in production but not in my test is that All Prayer requests are shown under #Gratitude-Society, and for some reason my #Gratitude for Significant other also showed up in

All prayer requests show up under #Gratitude-Entertainment and other gratitude as well.

For some reason all of my prayer requests show up under #Gratitude-Grandparents dispite not being written under that #tag. I don’t have any gratitudes last month for Grandparents because I did not spend any time with them or talk to them last month. so this should not appear in my monthly journal at all.

Test Notes

Now here in my Test Notes everything shows up exactly how I want them to. The Prayer requests only show up in the prayer request table, Gratitudes only show up under their headding, and empty gratitudes do not show up at all. Society Does not appear at the top of the list as none of my test notes have a note under #Gratitude-Society.


It’s difficult to test the “bug” without some example notes.
To start, don’t use

WHERE join(L.tags, "") = "#TagX"

or

WHERE join(L.tags, "#TagX")

(this one is doesn’t make sense).

Use only this format (replace in all your queries):

WHERE contains(L.tags, "#TagX")

If this does not solve the problem… well, then I don’t know where is the source of the issue.

Sorry @mnvwvnm I guess I could have put something in a past bin but I did not want to clutter the post on here with a whole bunch of text. You were right it was the join keyword that I needed to change to contains. It’s odd that the text files appeared to work. Maybe it was a fluke… I plan on putting together some test notes and publishing this on GitHub at some point. Will post in the showcase form when I do.

1 Like

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