Overall, I am trying to create a meaningful yaml front matter structure for easy querying. In more detail, I would like to generate a yaml structure to query nested key-value pairs. The pairs correspond to dates (year, month, day) and a value.
E.g.,
---
year:
1990: 3
1991: 4
1992: 5
---
Things I have tried
I would like to create the following table:
1990
1991
1992
3
4
5
I have managed to fetch a single year using:
TABLE year["1990"] as "1990"
WHERE file = this.file
I assume I need to FLATTEN my metadata, but I don’t manage to create the desired output.
TABLE year
FLATTEN year
WHERE file = this.file
I’m very open to suggestions how to structure my yaml frontmatter, e.g., not using key-value pair objects. Is there any good practice how to structure yaml frontmatter containing dates (years, months, days) and corresponding values, to make them easily queryable using dataview?
@cheezopath as a follow up question, how should i structure my yaml front matter and query if i would like to add another level? let’s say i would like to add a countries layer:
---
countries:
- name: A
years:
- year: 1990
value: 3
- year: 1991
value: 4
- year: 1992
value: 5
- name: B
years:
- year: 1990
value: 10
- year: 1991
value: 40
- year: 1992
value: 50
---
```dataview
TABLE WITHOUT ID country.name as name, country.years.year as year, country.years.value as value
WHERE file = this.file
FLATTEN countries AS country
```
depending what you’re doing, it might make sense to have one note per country, and if you want to get much more complex it’s definitely worth looking at dataviewjs
works like a charm, many thanks! now i understand better how to structure the yaml frontmatter. but let’s see if i manage to get to where i want, it’s trial and error. i have even less knowledge of dataviewjs, so i try to avoid it…