YAML key, multiple values, dataview table with one value only

If a key has multiple values, is it possible to only list one value in a table?

With the example below, is it possible for the table only to list Granada without also listing the names of the other cities at all?

tags:: #peninsulafilms  
film:: [[La Peninsula]]  
year:: [[2020]]  
locations:: "[[Madrid]]", "[[Barcelona]]", "[[Granada]]"

Table 1

```dataview
TABLE WITHOUT ID
film as Film, year AS Year, locations as Location
FROM #peninsulafilms 
WHERE contains(locations, "Granada")
FLATTEN locations
SORT year DESC, title ASC
```

Table 2

```dataview
TABLE WITHOUT ID
film as Film, year AS Year, locations as Location
FROM #peninsulafilms 
WHERE contains(locations, "Granada")
SORT year DESC, title ASC
```

Thanks for any tips.

Angel

1 Like
```dataview
TABLE WITHOUT ID film as Film, year AS Year, "[[Granada]]" as Location 
FROM #peninsulafilms 
WHERE contains(locations, "Granada") 
SORT year DESC, title ASC 
2 Likes

A million different permutations, but I hadn’t tried that one.

From the remaining fragments of my shattered mind … THANK YOU. So brilliant I could weep.

Angel

Hi.

Sorry for my intrusion…

I’d like to say three things:

  1. In inline fields you don’t need to use quotes if multiple values are links:
locations:: [[Madrid]], [[Barcelona]], [[Granada]]
  1. For links you don’t need to use the syntax for strings (the quotation marks) in the commands. Instead of WHERE contains(locations, "Granada") use WHERE contains(locations, [[Granada]])

  2. To a rigorous query, instead of the “construction” of the column results ([[Granada]] as Location) you need to apply the filter function:

TABLE WITHOUT ID
	film as Film, year AS Year,
	filter(locations, (l) => l = [[Granada]]) as Location
FROM #peninsulafilms 
WHERE contains(locations, [[Granada]])
SORT year DESC, title ASC
7 Likes

Thank you very much. Greatly welcomed.

I had looked at filters in the online docs but not been able to make sense of them. Clear explanations and examples like yours help enormously.

In terms of syntax for inline fields, are commas needed between tags (and at the end of them):

tags:: #books, #films, #addresses, 

OR (no closing comma)

tags:: #books, #films, #addresses

OR (no commas at all)

tags:: #books #films #addresses

They all seem to work. I have tried lots of web and forum searches but not been able to find an answer.

Muito obrigado

Angel

Hi.

They all “seem” to work… as “free” tags, not as an inline field with multiple tags.

  1. to check the differences (in fact, to check all metadata in your file) use this inline js query:
`$=dv.span(dv.current())`
  1. tags in inline fields work too as generic tags in your file (as the tags you place anywhere in your content), i.e., they are implicit metadata at page level. As page level data (file.tags) they are by default a list/array. In this way, you can place your tags inside an inline field or outside… for implicit fields is the same (because you target file.tags, not tags)

  2. If you use tags::, in the $=dv.span(dv.current()) results you’ll see at file level the field tags (file.tags) a list of tags. But you’ll also see a custom field called tags (but to avoid any confusion you can change it to tata) with your tags, not AS A LIST, but as a simple string with three tags inside. To the inline field tags(or tata) you have a string with tags inside. If you want that tags inside as a list you need to use the format

tata:: "#books", "#films", "#addresses"

But for “real” tags you don’t need an inline field… Outside the yaml frontmatter, just place your tags where you want. For example:

film:: [[La Peninsula]]  
year:: [[2020]]  
locations:: [[Madrid]], [[Barcelona]], [[Granada]]
#books #films #addresses #peninsulafilms
3 Likes

Thank you very much for the detailed reply. I learn a little more each day and find myself going back over notes and queries to refine them.

The jigsaw of my brain still doesn’t intuit when to use square brackets, commas, quotation marks, parentheses, etc.

And although I read the docs, I still fumble over arrays, strings, fields, values, and so on. I look at abstract examples and fail to apply them to the particularities of my data.

I enjoy the challenge, despite the frustration of being so slow.

Think a lot of people would be lost when dealing with Dataview without the help you give.

:clap::pray:t5::clap:

Awed and grateful.

Angel

1 Like

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