Dataview: finding keys without values

Aloha,
My apologies if this is basic, but I’ve been unsuccessful with the documentation and forums…

What I’m trying to do

Output a table including a key that includes instances where the key is lacking a value.

I have a template with a "Next Step:: " key. When I query, I want to make sure I’m getting all my next steps into my table, even ones where I may not have assigned my next step…

Things I have tried

Attached simplified screenshot:


I would like to be able to capture the notes that have the key, but are lacking a value. That way I can easily find where I’m missing next steps (or in the screenshot, where I’m missing testkeys)

Null works in local tests, as below.

WHERE testkey = null

Works for you?


Yeah, I tried that. It brings in every note in my vault (or whatever folder you’re querying). Not just the ones that have the key with no value…


In this particular vault, I have only two notes with the key “testkey”, yet “WHERE testkey = null” pulls in the entire vault.

1 Like

Regex could look for the key and then ‘nothing’, showing which files have the key without a value:

```query  
/Next Step::[ ]{0,}\n/  
```

Expect someone will know how to do this in Dataview.

1 Like

Hey hey hey! That’s a good enough solution for now! Mahalo!

1 Like

Noʻu ka hauʻoli :smile:

A DataviewJS option

In essence, DQL query are not able to distinguish between a non-existent field or a null value, as the other replies have shown. However, if you’re able to switch to dataviewjs you can detect where it has no value.

You’re still potentially going to run into issues related to upper- and lowercase character as long as you’re using field names with spaces, so be forewarned on that issue.

This version is not insensitive to the case of the field:

```dataviewjs
dv.list(dv.pages()
  .where(p => p.hasOwnProperty("Next Step") && 
              !p["Next Step"])
  .file.link)
```

Whereas this version, utilises the fact that dataview normalises the keys for you to allow for case-insensitive definitions:

```dataviewjs
dv.list(dv.pages()
  .where(p => p.hasOwnProperty("next-step") && 
              !p["next-step"])
  .file.link)
```

DQL workaround

If you want a table to show both values and you want to keep using DQL, you need to pre-populate the field with a known null-value. Like defining it to some random value, which is not going to be used elsewise.

That is you could set it to “n/a” or “not defined” or even “-” would work. This will give it a value, and allow for your queries to include rows with that “empty” value for Next Step.

Such a workaround might need some extra logic, in case you want to present the next step if only it has a value, and so on. But it’ll show in the tables where you need to locate those without a proper next step.

1 Like

Perfect. Thanks. I’ve yet to dive into dataviewjs.

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