How to get just the section header text in a table, not the whole section text

What I’m trying to do

Create a dataview Table query that lists file links and the header text for headers in the file.

If the notes of interest were formatted with fields, then this query would work:

TABLE focal-moment as "Focal Moment"
FROM "Research"
WHERE focal-moment

But for the many notes of interest instead of "Focal Moment:: we have ## Focal Moment a whole bunch of text

So for this:
## Focal Moment
A bunch of text interesting to linguists, like " “Amy claims to know X, but Jane says she doesn’t know X”
The table would contain:
File (4) Focal Moment
file name “Amy claims to know X, but Jane says she doesn’t know X”

Once that works, add a WHERE clause limiting the displayed headers to just headers containing some text, like WHERE = “Focal Moment”

Things I have tried

TABLE file.lists.section
FROM "Research/Test Headings"

This produces:

File1 file.lists.section
Test Headings * Test Headings > Focal Moment


TABLE file.lists.section
FROM "Research"
where icontains(file.lists.section, "focal")

Produces no results because the WHERE isn’t working.


TABLE file.lists.section
FROM "Research"
where file.lists.section = "Focal Moment"

Also produces no results.

Any help will be much appreciated.

Have you tried using something like

TABLE file.lists
FROM "Research/Test Headings"

to see all possible options you get from lists? Instead of lists.section or lists.header for example, you can use lists.text which returns the actual text of the heading section. You can also then use that in the WHERE condition too if you want to match text in the section body or just use the header in the WHERE as you are doing now.

Thank you this helped, but I’m still stuck.
First, I noticed what seems to me to be a bug, but it probably working as designed. I created the [[Simple Test Headings]] file. Headings will not be recognized if they only have plain text after them. They must have at least one bulleted or numbered list under them to be recognized as a list themselves, and so to appear in the queries below.


Heading 1

  1. some heading 1 text.

Heading 2

I. some heading 2 text

Heading 3

a. some heading 3 text

Heading 4

  • some heading 4 text

I got just the heading text to display, but could not get a WHERE clause to work:
Table of the lists text. Only shows for Heading 1 and Heading 4, because Heading 2 and Heading 3 do not have a bulleted or numbered list in their text.

TABLE file.lists.text
FROM "Test Files/Simple Test Headings"


Table of the lists.header

TABLE file.lists.header
FROM "Test Files/Simple Test Headings"


And now lets add a WHERE clause

TABLE file.lists.header
FROM "Test Files/Simple Test Headings"
WHERE contains(file.lists.header, "Heading 4")

Here are more WHERE clauses that return no results

  • WHERE contains(file.lists.header, “Heading 4”)
  • WHERE file.lists.header = “some heading 4 text”
  • WHERE file.lists.header = “Simple Test Headings > Heading 4”

My only wild guess at this point is that “file.lists.header” is not being evaluated in the WHERE clause, or at least is not being evaluated the way I expect.

Any further thoughts?
And again, thanks for your suggestions

It is indeed working as designed. AFAIK, in Dataview there’s no easy way to get text of an entire section. What it does have, which we are using here, and the hint is in the name file.lists.header. We are working with the lists property of the file object. The documentation mentions that this only fetches lists and tasks (which are just a type of list). So fetching heading 2 and 3 in your example would be not possible this way.

Regarding the where clause issue, can you try if this works

FROM "Test Files/Simple Test Headings"
FLATTEN file.lists.header as H
WHERE contains(string(H), "Heading")

There are two things different here, we are using the string() function before comparing the header and using FLATTEN to get each header in a separate row.

That works like a charm! Many Thanks I especially appreciate the explanation, as good explanations like this prevent hours of fruitless experimentation.

1 Like

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