What I’m trying to do
Given an inline field with it’s value as an internal link, or a list of internal links, as the below:
title:: “Bullet Train”
year:: [[2022]]
cast:: [[Brad Pitt]], [[Joey King]], [[Sandra Bullock]]
I’d like to utilize Dataview to filter out notes with a field cast
containing Brad Pitt
. Or, I just like to filter out notes with year
in 2022.
PS. The reason I use inline field instead of frontmatter is because the later doesn’t support internal links
Things I have tried
First, I tried a straightforward query through Dataview Query Language:
TABLE title, year
FROM "#movie"
WHERE contains(cast, "Brad Pitt")
SORT year DESC, title ASC
The queried result is empty.
Then I removed all internal links, just make them a plain text (or a list of plain text), like this.
title:: “Bullet Train”
year:: 2022
cast:: Brad Pitt, Joey King, Sandra Bullock
And then it just works.
There is probably something about data type or data value I have confused. Asking for your wisdom to guide me solve this ;p
Thx.
Just a quick idea without having tried myself:
Does the following work?
WHERE contains(cast, "[[Brad Pitt]]")
Otherwise the contains argument should probably somehow be told to also check for substrings.
That’s a good guess, and I gave it a try. No luck here.
EDITED on Tuesday, 19 April 2022: Please ignore this post and read this one instead .
This seems to work…
tags:: #movie
title:: "Bullet Train"
year:: [[2022]]
cast:: "[[Brad Pitt]]", "[[Joey King]]", "[[Sandra Bullock]]"
```dataview
TABLE title, year, cast
FROM #movie
WHERE contains(cast, "Brad Pitt")
SORT year DESC, title ASC
```
The ‘cast’ column can be removed, of course.
Angel
Based on the advice given in this post , the YAML and dataview queries below are more robust.
%%
tags:: #movie
title:: [[Bullet Train]]
year:: [[2022]]
cast:: [[Brad Pitt]], [[Joey King]], [[Sandra Bullock]]
%%
Film Title
```dataview
TABLE
title AS Title,
year AS Year
FROM #movie
WHERE contains(cast, [[Brad Pitt]])
SORT year DESC, title ASC
```
Film Title and Filtered Cast
```dataview
TABLE
title AS Title,
year AS Year,
filter(cast, (l) => l = [[Brad Pitt]]) as Cast
FROM #movie
WHERE contains(cast, [[Brad Pitt]])
SORT year DESC, title ASC
```
Angel
4 Likes
system
Closed
May 7, 2022, 5:01am
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.