Dataview: make a table with a separate row for different values of a key

What I’m trying to do

I have notes with several instances of the same key but a different value.
I was hoping to have a dataview query that makes a row, repeating the file name, for every instance of the key.
I want to order both filename and key.

Example sample note:

# 1 January 1400

- Time:: 14:00
- Scene:: DT-01.01.01
- Summary:: Summary 1

- Time:: 16:00
- Scene:: DT-01.01.02
- Summary:: Summary 2

- Time:: 22:00
- Scene:: DT-01.01.03
- Summary:: Summary 3

So far I have this query:

Table Time, Summary
From "Path-where-these-files-live"
Sort file.name asc, Time asc

This gives me a table ordered by file.name, and in the second and third column a bullet-list with the values of the corresponding keys.

I’d like to have three rows, repeating the filename, for each instance of Time

Hi.
One thing is “what we want”, other thing is “what is possible” or “what we can achieve with the created structure of metadata”. :slight_smile:
Considering your custom metadata:

- Time:: 14:00
- Scene:: DT-01.01.01
- Summary:: Summary 1

- Time:: 16:00
- Scene:: DT-01.01.02
- Summary:: Summary 2

- Time:: 22:00
- Scene:: DT-01.01.03
- Summary:: Summary 3

This is equivalent to:

Time:
  - 14:00
  - 16:00
  - 22:00
Scene:
  - DT-01.01.01
  - DT-01.01.02
  - DT-01.01.03
Summary:
  - Summary 1
  - Summary 2
  - Summary 3

So, the only groups you have are by fields (an array/list of values in each field).
There are no “pseudo-groups” Time-Scene-Summary, this means, for example, there’s no direct relation between Time:: 14:00, Scene:: DT-01.01.01 and Summary:: Summary 1… only the order/position.

We can try something with that, but isn’t a simple one.
To do that you need to add a header to each group. For example:

## part 1
- Time:: 14:00
- Scene:: DT-01.01.01
- Summary:: Summary 1

## part 2
- Time:: 16:00
- Scene:: DT-01.01.02
- Summary:: Summary 2

## part 3
- Time:: 22:00
- Scene:: DT-01.01.03
- Summary:: Summary 3

The query to test the new structure:

TABLE WITHOUT ID rows.file.link[0] AS File, rows.L.Time[0] as Time, rows.L.Scene[1] as Scene, rows.L.Summary[2] as Summary
FROM "your-folder-path"
WHERE file.lists
FLATTEN file.lists AS L
WHERE contains(meta(L.section).subpath, "part")
GROUP BY file.name + meta(L.section).subpath
SORT rows.file.name ASC
4 Likes

Thank you so much… that was exactly what I was aiming for.

As a new user I’m so impressed with the versatility of Obsidian, Dataview and other plugins. I’m also impressed with how quickly you came up with a solution.
And now I’m going to find out what each element of this query exactly does and why/how it works.

Thanks again.

1 Like

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