Dataview Inline Query Errors if Property Doesn't Exist

I’m trying to create an inline dataview query that does some math on a frontmatter property and returns a number. Works great when the frontmatter property has a number value, and even works if the property is blank, but I can’t get it working if the property doesn’t exist.
Here’s what’s working to pull a number from the property ‘hello’, do some math on it, and return 0 if the property is blank:

`=round( (default(this.hello,0) / 78) * 100,0 )`

When the property ‘hello’ doesn’t exist, I get the error:

“No implementation found for ‘null / number’”

I modified the query to try and prevent the math from happening if the property doesn’t exist, with no success:

`=choice(this.hello = null,0,round( (default(this.hello,0) / 78) * 100,0 ))`
`=choice(!this.hello,0,round( (default(this.hello,0) / 78) * 100,0 ))`

I’ve tried a number of variations on this with no luck. Any ideas on how to just return 0 if the property doesn’t exist?

Either of these variants seems to work:

`=  round(default(this["hello"], 0) * 100 / 78) + "%"`

`=  choice(this["hello"], round(default(this["hello"], 0) * 100 / 78) + "%", "not defined") `

As to why it doesn’t work in the other variants, I can just guess it’s related to variable expansion in the query. Using a keyed syntax like I’m using here ensures a different interpretation which isn’t actually null on the same behaviour.

Wow, I never would have guessed to try that, but it works, thanks!

1 Like

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