Dataview queries that use a variable defined elsewhere in a note?

What I’m trying to do

I have a note that contains several dataview queries. I would like to be able to have each of these queries contain a statement like WHERE x, where x is a variable defined at the top of the note holding a value for a tag, such as e.g. #source/video or #source/article. This way I could easily pivot the multiple dataview searches in this note just by changing x at the top of the note.

The alternative of creating a separate note for each possible value of x is cumbersome, especially given that I change the dataview queries occasionally and would like to avoid having to repeat such changes manually across many notes each time.

Things I have tried

Did an internet search for similar previous queries but didn’t find any.

if you use dataviewjs, you could poke a string into your query and execute that way.

For example, here’s a familiar query wrapped in dataviewjs

dv.execute('LIST FROM #todo LIMIT 5')

but you could just as easily add a variable from the page:

dv.execute('LIST FROM '+dv.current().x+' LIMIT 5')

assuming you had x in your frontmatter or as an inline variable and it was a valid source (in string form)

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