Dataview plugin snippet showcase

I have not been able to get a query where multiple fields in one note are shown in a query. Only the last record in a note will be shown. So … if anybody could that working I would be very interested also.
(without falling back on multipage dataviewjs queries)

This was implemented in 0.3.10.

Thank you @Rishi… but this doesn’t work, either.

Two problems here:

  1. WHERE GAO.When = this.file.link doesn’t match.
  2. Removing the WHERE clause, just the last
GAO:
  When: [[2021-06-02]]
  What: [[Topic-name]]

is shown. In other words, if I put

GAO:
  When: [[2021-06-02]]
  What: [[Topic-name-1]]

GAO:
  When: [[2021-06-02]]
  What: [[Topic-name-2]]

in my YAML frontmatter, just the second is shown.

That is invalid YAML I am certain. Parsing it removes the duplicates and retains the last one. The feature which was implemented in Dataview 0.3.10 (and I tested it again) works only with inline dv fields and not YAML.

Regarding the first one, it works on my end. Here’s how I tested: In one file, I have your YAML with duplicate GAOs. Then I use this same query in two different files, one with daily note where it should match the condition and one where it shouldn’t.

TABLE GAO, g
FROM ""
WHERE GAO.When = this.file.link

This is the source file

Dataview output for both files with edit and preview on left and right respectively

First of all: @Rishi, thank you so much for your time, seriously!

Then:

  1. When I duplicate the GAO structure in the YAML frontmatter, Obsidian doesn’t say “invalid YAML”, but yes, it just retains the last one.

  2. I would prefer not to put them in the YAML frontmatter, but in this case (inline) how can I have field.subfield? According to my knowledge, this is not possible inline. Am I wrong (I really hope so!)?

My final goal is to show just What, provided When is matched.

You’re welcome! You are right, inline fields don’t support subfields unless there’s some syntax I’m unaware of. They do allow lists but the way where works with a list, we can’t just use contains() to find a substring from a list. I also thought perhaps using the When date as a key might work for YAML but that’s not supported either.

I can’t think of anyway to solve this except for using separate notes for each entry.

P.S. Have you considered just adding a GAO: [[2021-06-03]] to the note for the book/website?

Oh, sorry to be… right!

Let me better explain my use case, because I believe it’s not a strange one. So a work around it could be of interest for many.

Today I start to read Book_1. Then I write a new note for it, filled with all the usual stuff (author, title, etc.). At a certain point, reading it I Get Aware Of (GAO) an interesting Topic_1. Consequently, I’d like to keep track that this happened today, reading Book_1.

Tomorrow, reading Book_1 I’ll GAO an interesting Topic_2. Etc.

In today’s daily note I’d like to have all the interesting things I discovered… today! Topic_1 from Book_1, for sure, but also (say) Topic_3 form WebSite_1, etc.

In tomorrow’s daily note, Topic_2 from Book_1, etc.

(OK, as you all guessed, English is not my mother-tongue…)

:smile:

I see what you are trying to do. I do something very similar. I keep a log of things I have read and watched and this is how I track it, taking your example above.

Say I read Book_1 today and discover the Topic_1, this is what goes in my daily note:

- #Read:: Started reading [[Book_1]] recommended by [[kenNash]] and came upon the realisation that [[Topic_1]] is interesting.

I’ll then click on [[Topic_1]] to write something about it. And in that note, I’ll add the YAML GAO: 2021-06-03.

At the end of the day, I’ve dates for both the activity of reading the book as well as for creating the topic originating from/inspired by the book. Although the book and topic are not directly linked, they are linked through the daily note. That can be easily fixed if you decide to add a Source field to the topic. I’d suggest doing that outside of YAML since links in YAML don’t show up in backlinks. With that, all the three entities (daily note, book note, topic note) either link to each other or have a backlink.

Continuing to the next day, my daily note might look like,

- #Read:: Read chapter 3-4 of [[Book_1]] and it made me think of [[Topic_2]]

And follow the same process for [[Topic_2]]

Once this process is setup, I’d then create a new note for all my reading logs and call like Reading Log with a Dataview query to aggregate it all,

TABLE Read
FROM #Read
WHERE Read
SORT file.ctime DESC

It should look something like this (screenshot from my Watched Log

And for your specific use case of the GAO, I’d create another GAO Log note and use something like this in there,

TABLE GAO, Source
FROM #topic OR "ZK"
SORT file.ctime DESC

This should give you all topic notes most recent first, along with their GAO date and Book. Note that you can add multiple dates in the GAO YAML field and also multiple Sources in the Topic file in case you rediscover the same idea later from a different book. Dataview will show those as a list (you just need to ensure that you enter them both in the same order). You can see this from my screenshot where sometimes I watch multiple things during the day and it is shown just fine.

If you notice I’m using a tag for the Read key for Dataview. I do that so that it serves dual purpose. #Read:: works both as a Dataview inline key as well as a regular markdown tag. So if I’m working on my vault in another app (or if Obsidian goes away sometime in the future), I can still at least search for all these lines easily. Plus I also have a regular query in my log files which is simple like,

```query
tag: Watched

I keep this around because it gives me better context around the lines but the Dataview query allows me to sort and show multiple fields in columns.

Hope this gives you (or others) some ideas for a logging workflow.

6 Likes

This morning I was trying to show only files with a folder depth of 2. I figured out this regex:

It can be simplified, but I left it that way so you can change the depth easily. set the {1,2} to {2} and it will only show those on the 2nd level. Or you can do {1,5} and it will up to 5 levels deep.

Here is how I use it:

```dataview
table file.path, file.name from "1. Projects"
WHERE regexmatch("^1. Projects(\/[^\/]+){2}$", file.path)
```

I wanted to show only the files inside project folders, but not the sub folders of project folders

2 Likes

Do you know if there’s a current workaround to search for file names containing certain strings in Dataview?

Figured it out using regexmatch! Here’s an example of my solution to search for a string within a file name and also to exclude strings from searching file names:

```dataview
list from ""
where regexmatch("^.*title-string-to-search-for", file.name) and regexmatch("^((?!title-string-to-exclude).)*$", file.name)
```
3 Likes

There is also a simple
where contains(file.name, "string")
that has worked for me in the past.

2 Likes

Hi there, do you know what to include in the parentheses so the regex ignores case. I’m trying to look for certain word in file name, but don’t want the case to cause the query to miss the file. Thanks much!

And another question: is there a way to use an OR AND in there too. So list notes with “stringA” or “stringB” in file name?

Thanks again.

1 Like

Maybe I should put this in the “Help” category, but you all are so knowledgeable :slight_smile: and maybe someone has come across this before.

I started to use dataview for creating a sort of annotated bibliography for projects. In my literature notes, I have an inline “Abstract” field, and then have a note where there is a simple table just with the abstracts for the project.
It seems that it only works with a certain length of abstracts (around 70 words? I have not narrowed it down precisely); if it’s longer, then it does not display in the table. Is there possibly any way to modify this max. length for an inline field?

Yeah, I got stuck trying to do the exact same thing. Apparently there’s a limit of 500 characters for an inline field.

Here’s the link to the Discord discussion.

2 Likes

Thank you, @Surjaa – I see. Always forget to check discord…
Well, here’s some motivation for short abstracts!

1 Like

@atiz I’m also trying to achive the transclusion of abstracts, but so far haven’t managed to.

I have tried the replacement below. It works, but I can’t get transclusion by adding "![[" instead of "[[". Maybe ! should be scaped in some way?

table ("[[" + file.name + "#Abstract]]") as Abstract, year
sort year desc

I have also tried to use DataView’s replace funcion. Below is what I have tried, though it doesn’t work.

table year as Year, rows.file.link as File
group by year
replace("]]", "#Abstract]]")
sort year desc

Your help will be appreciated.

Hi @jmm, I think I chose a slightly different approach to this.
Instead of putting the abstract in its own section, I put it in an inline field under the title, like this:

abstract:: here goes the abstract/summary of the paper

The advantage is that since it’s an inline field, you can invoke it very easily from dataview; my table looks like

```dataview
table abstract as Abstract
from #project
sort author asc

The disadvantage is what’s above: seems like the default line length for the dataview table is capped at 500 characters. The good news is that that seems to be modifiable (per @Surjaa’s link to the discord thread; you can edit the plugin and increase this size, although will have to do it every time it updates. I haven’t experimented with this yet, so this is just based on the discord thread).

I like your approach too, but I’m really not very fluent in dataview yet so would have to experiment to see how transclusions work in it if they do.

3 Likes