# Query from lists using dataview

**URL:** <https://forum.obsidian.md/t/query-from-lists-using-dataview/23881>\
**Category:** Basement\
**Tags:** dataview\
**Created:** [September 8, 2021, 4:34pm UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881 "2021-09-08T16:34:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dutyfreemind](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@dutyfreemind](https://forum.obsidian.md/u/dutyfreemind)\
**Post date:** [September 8, 2021, 4:34pm UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/1 "2021-09-08T16:34:19Z")

</div>

### What I’m trying to do

Hey everybody,  
I am trying to define a key with a list of values in yaml front matter (or in-line, see below), and then use dataview to make a list (or table or whatever) of all files that contain one specific value in that list. e.g.:

the front matter bit:

```
---
type: book
copy:
- library1
- library2
- personal
---

```

and the dataview query:

````
```dataview
LIST
FROM "books"
WHERE copy = "library2"
```

````

somehow, dataview and/or yaml don’t seem to accept the lists I define. If I use only one value, it works fine. as you can probably guess, I organize my literature with obsidian and I want to note in which libraries I can find a particular book and then generate lists for each library so I can see what to get on my library visits.

what I’d like even better would be using standard obsidian tags instead of front matter, cause the former offer auto-complete, so I don’t have to remember all the shorthands for the libraries. Is there a any way to achieve this?

### Things I tried

I also tried to define the lists with square bracket, without brackets just separated by commas and inline key-value pairs (key:: library1 library2 etc).

It would be so cool if anyone could point me in the right direction to make this work. Thanks!

---

<div class="post-metadata">

**Author:** ![mnvwvnm](https://forum.obsidian.md/user_avatar/forum.obsidian.md/mnvwvnm/32/9766_2.png) [@mnvwvnm](https://forum.obsidian.md/u/mnvwvnm)\
**Post date:** [September 8, 2021, 5:03pm UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/2 "2021-09-08T17:03:12Z")

</div>

By parts…

1. Using frontmatter fields

- To arrays, you need to add two spaces before “-”

```auto
---
type: book
copy:
  - library1
  - library2
  - personal
---

```

1. Dataview query

- If you want to filter one of the array elements, you need to use the function `contains(field, "value")` (you can use `copy = "library2"` if you have only one value, not a list/array).
- Try this query:

````auto
```dataview
LIST
FROM "books"
WHERE contains(copy, "library2")
```

````

1. Using tags

- If, instead of frontmatter values, you prefer using tags (#library1, #library2, …) anywhere in your file, you can use for the query the implicit field `file.tags`… or, more simple, define tag as the source (`FROM #tag`).
- Try this query

````auto
```dataview
LIST
FROM #library2
```

````

* * *

EDIT: You can use multiple source filters. So, if you want keep the filter to folder “books” just compose the source filter with the expression `FROM "books" AND #library2`

---

<div class="post-metadata">

**Author:** ![anon12638239](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@anon12638239](https://forum.obsidian.md/u/anon12638239)\
**Post date:** [September 8, 2021, 8:59pm UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/3 "2021-09-08T20:59:28Z")

</div>

Hello.

The YAML sample in [Obsidian Help](https://help.obsidian.md/Advanced+topics/YAML+front+matter) doesn’t use spaces in arrays, and the OP’s YAML works in the sample note attached without using spaces.

But is it better to use spaces in arrays?

Thanks

Angel

[SampleNote.md](https://forum.obsidian.md/uploads/short-url/1Mq64EBDYoalS4R05K9IpimtTpN.md) (407 Bytes)

---

<div class="post-metadata">

**Author:** ![mnvwvnm](https://forum.obsidian.md/user_avatar/forum.obsidian.md/mnvwvnm/32/9766_2.png) [@mnvwvnm](https://forum.obsidian.md/u/mnvwvnm)\
**Post date:** [September 8, 2021, 9:39pm UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/4 "2021-09-08T21:39:46Z")

</div>

Hello.

For Dataview plugin in particular, following the advice from some ‘code experts’, it’s more advisable to use the two spaces (because “YAML is an indentation-based markup language”).

The same for ‘nested’ keys/fields [Dataview Documentation](https://blacksmithgu.github.io/obsidian-dataview/data-annotation/):

```auto
field1:
  field2: value1
  field3:
    - value2
    - value3

```

---

<div class="post-metadata">

**Author:** ![anon12638239](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@anon12638239](https://forum.obsidian.md/u/anon12638239)\
**Post date:** [September 9, 2021, 5:23am UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/5 "2021-09-09T05:23:26Z")

</div>

Brilliant.

Thank you very much for the explanation and link.

I learn. Slowly.

Angel

---

<div class="post-metadata">

**Author:** ![anon12638239](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@anon12638239](https://forum.obsidian.md/u/anon12638239)\
**Post date:** [September 9, 2021, 7:13am UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/6 "2021-09-09T07:13:44Z")

</div>

The official [YAML specs](https://yaml.org/spec/1.2/#id2777534) say:

> In YAML structure is determined by _indentation_. In general, indentation is defined as a **zero or more space characters** at the start of a line.

So if indentation can start at zero spaces, I guess that’s why the example in Obsidian Help uses zero spaces; although the dataview examples differ.

At least both methods appear to work with dataview.

Consistency of indentation in a document seems to be critical.

Thanks again for your help and time. No need to reply. Just sharing what I read for anyone else who might read this thread.

Angel

**EDIT**

Curiously (to me, anyway) the Obsidian Help example uses hyphens, but the dataview documentation doesn’t.

My head 🤕

---

<div class="post-metadata">

**Author:** ![dutyfreemind](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@dutyfreemind](https://forum.obsidian.md/u/dutyfreemind)\
**Post date:** [September 10, 2021, 6:42am UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/7 "2021-09-10T06:42:38Z")

</div>

Thanks mnvwvnm! The last one is so simple, I should have thought of it myself 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [September 11, 2021, 6:43am UTC](https://forum.obsidian.md/t/query-from-lists-using-dataview/23881/8 "2021-09-11T06:43:05Z")

</div>

Closed on September 11, 2021, 6:43am UTC

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