How to query a note with multiple values in a YAML key?

Hello, fellow Obsidian users.

So let’s say I want to write a note about a fictional character and an event that he experiences.

In John.md, for example, there is this Dataview query:

list from #plot
where actor = "John"
sort file.name

In an event note, “John meets Jane.md”, there is this frontmatter:

---
tag: plot
actor: [John, Jane]
---

Now, the problem is that the Dataview query in John.md doesn’t list “John meets Jane.md”, whereas when I change it to…

---
tag: plot
actor: John
---

…it is being shown.

How could I let the event page detect the character page and still let the actor key have multiple values?

I’ve tried different symbols for the list, like semicolons, regular brackets, no brackets, apostrophes, …

Thank you for your help in advance!

1 Like

You don’t get “John meets Jane.md” because if actor: [John, Jane] then actor = "John" is false. «equal» means «equal» and in that case John is one of the values in a list…
For that you need to use the function contains():

LIST
FROM #plot
WHERE contains(actor, "John")
SORT file.name

https://blacksmithgu.github.io/obsidian-dataview/query/functions/#containsobjectliststring-value

4 Likes

Forgive another stupid question, but:

And from here:

Why in this case don’t we need quotes like this:

Thanks

Angel

(sorry for the fast answer)

Am I incoherent? :slight_smile:

Yes, many times.

The question here (to not complicate the original request) is that you have values with simple words. You don’t have the risk to have a comma in the value (as the expression This is a single value, an expression with commas).

The answer in the linked post is “universal”, this one is “specific”.

2 Likes

I knew it was a stupid question, and now you have explained it to me I can see that it was a very stupid question.

Thank you very much for your time and kindness.

I think I should give up using Dataview and Obsidian. I am just too dumb. :frowning:

(Crestfallen) Angel

It helped! Thank you very much!

Don’t worry! It’s hard to comprehend Obsidian at first. I’m sure you’ll get this very soon.

1 Like

Please, no way.
You are one of the best helper here.
Your questions are rational, valid doubts.
And “rules” are just that, human constructions with many unstable foundations…
(my incoherency is so stupid as your question. Are they?)

3 Likes

You are never incoherent. You know that I (and many others) greatly admire your knowledge and kindness.

The answer I needed was already there in front of my eyes but somehow my brain hadn’t engaged.

Have a good weekend.

Angel

2 Likes

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