How to query the tasks (1) having a particular field value and (2) whose goals have a particular field value?

Say I have the notes GoalA, GoalB, GoalC, GoalD, TaskX, TaskY, TaskZ like this:

  • GoalA:
    toTask:: [[TaskX]]
    toTask:: [[TaskZ]]
    field:: yes

  • GoalB:
    toTask:: [[TaskX]]
    field:: no

  • GoalC:
    toTask:: [[TaskX]]
    field:: yes

  • GoalD:
    toTask:: [[TaskY]]
    field:: yes

  • TaskX:
    key:: ok

  • TaskY:
    key:: ok

  • TaskZ:
    key:: not ok

Is there a way to query all tasks (1) which have key value ok and (2) whose goals have field value yes? And the second column would be only the goals with yes. The output would be:

|File |Goals|
|-----|-----|
|TaskX|GoalA|
|     |GoalC|
|TaskY|GoalD|

And what if the restraining information for the goals are not a particular field value, but the folder they are contained, or the string they start with?

This question is a next step of this one: Note A and B have `key::[[X]]`. I query X. How can I display A and B in the query?

If I understood your query correctly, I think you need to use the filter() command.

You can read more about it in the docs: Functions - Dataview

2 Likes

Hi!
@Craig’s solution is right.
But the condition key = "ok" is missing.

## Filtering field in goal

```dataview
TABLE
	file.inlinks,
	file.inlinks.field,
	filter(file.inlinks, (i) => i.field = "yes") AS Goals
FROM "tasks-folder-path"
WHERE key = "ok"
WHERE filter(file.inlinks, (i) => i.field = "yes")
SORT file.link ASC
```

---
## Filtering goal folder

```dataview
TABLE
	file.inlinks,
	file.inlinks.file.folder,
	filter(file.inlinks, (i) => i.file.folder = "goal-folder-path") AS Goals
FROM "tasks-folder-path"
WHERE key = "ok"
WHERE filter(file.inlinks, (i) => i.file.folder = "goal-folder-path")
SORT file.link ASC
```

---
## Filtering goal name

```dataview
TABLE
	file.inlinks,
	file.inlinks.file.name,
	filter(file.inlinks, (i) => startswith(i.file.name, "Ooker")) AS Goals
FROM "tasks-folder-path"
WHERE key = "ok"
WHERE filter(file.inlinks, (i) => startswith(i.file.name, "Ooker"))
SORT file.link ASC
```

Note: the first two columns are for test purposes… to see the values before the filter

3 Likes

thank you.

WHERE filter(file.inlinks, (i) => i.field = "yes")

In my understanding, filter() returns an array/list. Why does WHERE accept that?

WHERE evaluates the expression and looks for something that looks true or false. In the case of filter(), if the returned list has any values then it considers it a true result; if the list is empty it considers it a false result.

Because of this, the WHERE clause will filter out any pages where no backlinked pages have field=yes.

2 Likes

Practically this method allow to convert the markdown table in dataview?

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