Inline metadata query on the same page for many blocks/sections

Hello,
I’m trying to build a dataview query, to query the inline metadata from a single page, the same page in fact. And so far, I haven’t been able to find a solution that does what I was hoping for. I’m hoping that someone here can help me out, or confirm if what I’m trying to do isn’t possible.

Below is an example of the text I have on the page.

# Day 1
region:: Jardines Del Eden, Colombia 
variety:: Red Gesha
processing:: Natural 
rating:: 3/5 👎

# Day 2
region:: La Colina, Guatemala
variety:: Caturra
processing:: Natural
rating:: 4/5 👍

# Day 3
region:: Los Pirineos, El Salvador 
variety:: Pacamara
processing:: Black Honey
rating:: 3/5 👎

And below is the dataview query I currently have. However, I haven’t been able to figure out how to get this query to extract each section into its own row. So instead of having a row per “day” I currently have a single row, and it has many items in each cell.

TABLE WITHOUT ID section AS "Day", this.region AS "Region", this.variety AS "Variety", this.processing AS "Processing", this.rating AS "Rating"
WHERE file = this.file
GROUP BY day
SORT day

Any help would be much appreciated, thanks in advance. :pray:

When you’ve defined your inline fields there is currently no way to ensure that they belong to the same entity as they’re defined in the page context. If however, you choose to make them into lists/tasks you can start working with them as separate entity through the usage of FLATTEN file.lists as item. See thread below for a similar example:

I say currently, because there are work being done on a plugin called Datacore, which is meant to be the successor of the Dataview plugin. But I’m not sure when (or if) it’ll be released to the general public. One of the goals of this new plugin is to add new contexts like blocks/paragraph, and so on.


I’m not entirely sure how I would format the list to display the information you’ve got, but here is one option with a suitable query:

- (desc:: Day 1)  
  [region:: Jardines Del Eden, Colombia]
  [variety:: Red Gesha]
  [processing:: Natural]
  [rating:: 3/5 👎]
- (desc:: Day 2)  
  [region:: La Colina, Guatemala]  
  [variety:: Caturra]  
  [processing:: Natural]  
  [rating:: 4/5 👍]  
- (desc:: Day 3)  
  [region:: Los Pirineos, El Salvador]  
  [variety:: Pacamara]  
  [processing:: Black Honey]  
  [rating:: 3/5 👎]

```dataview
TABLE WITHOUT ID item.desc, item.region, item.variety, item.processing, item.rating
WHERE file = this.file
FLATTEN file.lists as item
WHERE !item.parent
```

Where the latter part (“day 3” and the query) looks like:

Sadly, there is a bug in dataview currently which triggers some pecularities when it displays the original list item, so as the image shows it says that the last entry has the same values as “Day 3”, but still it displays the correct values in the table (and of course in source mode). Columns can of course be renamed, I just kept them as is to display how/where I found the values.

The various fields can also be styled using CSS to your liking.

(( An alternate setup using subtasks to contain the extra information is depicted in this reply on another similar case. I kind of don’t like that query myself (even if I’m the author), as it does a lot of list handling to get to the result. ))

1 Like

Thanks very much for the reply @holroy! That worked nicely, much appreciated.

I ended up going with something based on the second example you linked, as I felt the data layout was nicer, and would be more forgiving of editing on the go in the mobile app as well.

Here’s what I ended up with, in case this is useful for others:

# Data layout
- Day:: 1  
	- region:: Jardines Del Eden, Colombia
	- variety:: Red Gesha
	- processing:: Natural
	- rating:: 3/5 👎
	- tasting notes:
		- Light, not acidic
		- Nutty
		- Scents of plum

# Dataview query
```dataview
TABLE WITHOUT ID item.Day as Day, Region, Variety, Processing, Rating
WHERE file = this.file
FLATTEN file.lists as item 
FLATTEN filter(item.children, (c) => c.region)[0].region as Region 
FLATTEN filter(item.children, (c) => c.variety)[0].variety as Variety 
FLATTEN filter(item.children, (c) => c.processing)[0].processing as Processing 
FLATTEN filter(item.children, (c) => c.rating)[0].rating as Rating
WHERE item.Day 
```

Thanks again for your help!

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