How do you code dataview query to take value of dataview field?

Things I have tried

a:: #blah

> WHERE contains(text, "a::")

…which was a wild guess, and not expected to yield an acceptable outcome. Suffice it to say that I tried something.

What I’m trying to do

Imagine you have a page with a dataview field and query as shown.

a:: #blah

> WHERE contains(text, "")

Also, imagine that somewhere in your vault there is a legitimate task, tagged with #blah, for example:

[ ] - dummy task #blah

How do you code the dataview query so that it automatically takes the value of a:: which in this case is #blah and puts it between the ""?

So, I want the following query, but I don’t want to manually type in #blah:

> WHERE contains(text, "#blah")

It follows that if I were to change the value of a:: the results of the dataview query would change accordingly.

Perhaps a solution requires dataviewjs. If so, what do you recommend?


I might be getting confused with how the forum displayed your examples. If so, my apologies for the unnecessary explanations below.

A TASK in Markdown/Obsidian/dataview is a line that starts:
- [ ] and then has some text describing your task. Instead of the space inside the brackets there might be a character there to indicate the task is done instead of not-done:
- [x] and then some text.
If your line does not start like that, it is not a task and will not show up in a TASK query no matter what you do.

If your line does start with the task formatting, you can use implicit dataview task fields like text and tags in your query.

Investigating how to answer your question
I like using TABLE queries to investigate what is happening while I am trying to get some other query to work. I usually limit to a small test file or folder while onvestigating so I do not get tons of results but you could also use something like LIMIT 10.

contains(Tasks.tags, this.a) AS "a in tags?",
contains(Tasks.text, this.a) AS "a in text?"
FROM "testFileOrFolder"
FLATTEN file.tasks AS "Tasks"
WHERE contains(Tasks.text, this.a)

I would probably start this table without the WHERE line, and then put it in once I have checked that the columns of the table match what I expect.

Does this help with figuring out what your query should look like? Good luck!

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