Dataview plugin snippet showcase

How did you get the book thumbnail to work? I tried, and it’s not working for me.

Thanks @dryice - really great stuff here! Helped me work out a lot of issues I was having.

One issue I’m having with sleep tracking calculation, where it gives me an incorrect duration. Let’s say in my Daily Note, I enter Sleep Hour for 3 (as in 3 AM), Awake Minute for 0. Awake Hour as 10 (as in 10 AM) and awake minute 30. The calculation it gives me is 31.5 hours rather than 7 hours. Not sure what I’m doing wrong here. Grateful if you could lend a hand here.

This here below is the calculation I’m using from your template

=round(sum(24 - sum(this.file.link.sleep-hour + (this.file.link.sleep-minute / 60)) + sum(this.file.link.awake-hour + (this.file.link.awake-minute / 60))), 4) hours.

Hi,

I uploaded my templates here if you want them. There might be some updates that you find useful.

Regarding your question,

  • use 24 hour time - 23 = 11 pm
  • and for hours past midnight, use 24, 25, 26 to indicate midnight, 1 am, 2 am…

:+1:

Also, we can make the code simpler

  • instead of this.file.link.sleep-hour
  • use this.sleep-hour which will do the same thing.
    • I think the .file part accesses the file metadata - re-reading the dataview docs would help me to understand and explain it better.

(I don’t have any programming background at all, so this is just my experience learning about dataview over the past months… And thus I am always interested in feedback.)

Do you plan to add any other features to your periodic notes?

Hi @allanelder

The code is selecting from any note in the vault where type = book, and status = reading.

It is displaying a table with columns author, cover, about… Etc.

In the cover column, an image should be displayed when the field cover:: contains a URL link to an image. I have had troubles in the past when using http:// addresses instead of https:// addresses.

cover:: https://m.media-amazon.com/images/I/51XP7Y9DWnL._SY177_.jpg

Could that be the issue?


As an aside, one could choose to change the code to reduce the FROM sample size to FROM #Media/Books. I don’t know if this improves performance.

1 Like

Using Dataview 0.4.21 or later you can query for tasks under a specific heading. For example if you have multiple project files which have “Next Actions” sections like this:

## Next Actions

- [ ] schedule a meeting
- [ ] write notes

You can show all of the tasks from all of those Next Action sections with this query:

```dataview
task
where meta(section).subpath = "Next Actions"
```

By default the tasks will be grouped by file. If you want them in one combined list you can add a group by clause like this:

```dataview
task
where meta(section).subpath = "Next Actions"
group by "" as ""
```

This works because each task has a section property which is a link to the specific section of the file where the task is written. The subpath property of the section link gives the heading text for that section. Normally when you access a property on a link you get the property value of the file that the link points to, not the property of the link itself. So section.subpath does not work. The new meta function provides a way to access metadata of the link itself; so meta(section).subpath gets the subpath property of the section link.

9 Likes

Thank you, @dryice, I was not using a web link but have the image local. Not that I understand how ("![coverimg|90](" + Cover + ")") pulls from a website.

Thanks! I didn’t see the 24 hour time. I updated the code with your template, but unfortunately I’m getting this message

Dataview (for inline query '=round(sum(24 - sum(this.sleep-hour + (this.sleep-minute / 60)) + sum(this.awake-hour + (this.awake-minute / 60))), 4)'): No implementation found for 'null / number'

I added the Sleep Hour, Minute and Awake Hour and Minute. Not sure how to fix this or why it’s returning null. Any tips?

A little question:
I use Deadline - date(today) to show days until the deadline.

Supposed the deadline is 2022-01-11, how can I make it show up like this?:
2022-01-11 (in 2 days)

In the string ("![coverimg|90](" + Cover + “)”) , the “+ Cover +” part gets replaced with the url/path for the image when the Dataview process runs!

1 Like

It is just breaking apart the![embedded](www.website.com) formatting. Hopefully that makes sense.

Hi there, can you check that you have numbers in all of the fields?

I make sure “0” is loaded into the minute field by the template. If a field is empty, it gives the null error that you experienced.

1 Like

Hi, I also just saw this update announcement for v0.13.19
“- Fixed embeds not rendered in plugin code”

I’m on my mobile atm… But I’m interested to know if this Field:: ![[image.png]] will now work?!

This worked thanks! For the 24 hour time - if you have fall asleep past midnight (let’s say 2 am), I imagine you would subtract the awake hour from the time you fell asleep (aka. 26 in this case), and not 24, to get the duration right? Just double checking I’m doing this right

Does anyone know why I am getting this error Dataview: Error:

Here is what I have for my dataview query

table WITHOUT ID
FROM #habit 
WHERE week = this.file.link
sort file.name asc

This is what I get as a result

– PARSING FAILED --------------------------------------------------

1 | table WITHOUT ID

2 | FROM #habit
| ^
3 | WHERE week = this.file.link
4 | sort file.name asc

Expected one of the following:

‘,’, /FLATTEN/i, /FROM/i, /GROUP BY/i, /LIMIT/i, /SORT/i, /WHERE/i, EOF

I keep having problems on the FROM line, sometimes it happens with #hastags and sometimes when I am trying to pull from a folder

Hi again!
You’ll need some columns to render it as a table.

TABLE WITHOUT ID field_1, field_2
FROM #Habits

Or change it to a list of files, and with a list I think you can display one field next to the file name.

LIST Field_1
FROM #Habits

Hello,

Is there any way to display a subtag only in a dataview table ?

E.g. :

#Type/Status → Display only “Status” in the dataview table.

Thanks !

Hi @JamesKF, I have a two solutions you can try. The first solution assume you only ever have one tag for the note.

TABLE
	regexreplace(tags, "^Type.*/", "") 
	AS "Type"
FROM #status
SORT file.name

This will give you the last word of the tag if the word Type is at the beginning. It doesn’t work well if you have multiple tags.

For multiple tags here is a possible solution. It is more verbose.

TABLE
	join(
		map(
			filter(
				split(tags, ", "), 
				(t) => startswith(t, "Type")
			),
			(tag) => regexreplace(tag, "^Type.*/", "")
		),
		" | "
	)
	AS "Status"
FROM #Type
SORT file.name

The tags are joined back together to make a string using the | character, change this to a comma if you would prefer.

5 Likes

Thanks a lot @StuMaynes for your detailed answer. I will add a reference to your post in the topic I created for this question.

Obsidian charts

HI Please may I ask for some help please for my Table queries? I been trying to get it to work but am not getting very far. Thank you for your time.

I mark all my notes relating to a person by using [[@name]], and this convention is used through out my database in all of the notes. So there are notes linked to a person, or in this person’s notes, there may be outgoing links to other notes.

I want to create a People index (Table) using Dataview, one the first column showing the persons name, the second column showing all the notes that mentions this person, and the third column all notes that this person’s note mentions.

I got as far as generating the first column using:

Table dateformat(file.mtime, “dd.MM.yy-HH:mm”) as “Linked Notes”
WHERE contains(file.name,"@")
Sort file.name ASC

But not sure how to proceed next… can anyone help please?

Note: the dateformate was just a dummy i used to test… so it is just a placeholder… thank you…