Using variables to make dataview query dynamic


I want to use a inline-variable inside a dataview-query, to be able to filter it.

e.g. I have these three notes:


Library: [[nutrition]]
category: fruit
effect: healthy


Library: [[nutrition]]
effect: healthy
color: red


category: drug
effect: not healthy

Now I want to use one dataview to query for both, for files, that have values inside the property “effect” and for files, that have values inside the property “color”.

For that, I would define a inline-metadata-variable, like:
var:: effect (or var:: color, if I would like to filter for files with that property)

with this dataview…

Table category, effect
Where this.var

and var:: effect, I would have expected, to get a table with three entries, apple, tomato and cigarettes (all three notes do have values in the effect-property)
With var:: color, I would have expected, to get a table with only one entry: tomato, because this file is the only one with a value in it.

… unfortunately, it seems like the Where expression doesn’t work at all… do you have an explanation for that?

Thanks in advance,
kind regards,


When the query is parsed it’s expanding out the various variables, and in your case that would lead to a WHERE "effect". In other words, it’ll check if the text “effect” is a truthy value, and not whether there exist a variable called effect.

Luckily there is an easy way around this (as long as we’re talking about single variables and not extended WHERE clauses, and that is to use the row[...] syntax, so try the following query:

TABLE Library, category, effect, this.var
WHERE row[this.var]

Thanks again holroy! :slight_smile:

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