Dataview plugin snippet showcase

Does anyone have examples of Group By?

I’m trying to figure out if what I want is possible. Assume a folder called Recipes, with subfolders like Appetizers and Drinks (I know I always use recipes but I find they work well with examples). I’d like the list to display as follows:

Recipes/Appetizers
item 1
item 2

Recipes/Drinks
item 1
item 2

I would actually prefer to hide the “Recipes” part of the path, but that’s a different matter.

This just gives me an empty list:

```dataview
list from "Recipes"
where file.name !="_Recipes TOC"
group by file.path
```
1 Like

Hey Lise. You can read my post here for a longer description of group by.
But basically, I think your codeblock should work with a minor change.
You’ve grouped the recipes properly, but now you need to ask for them to be displayed. You do this with the rows property, which I discuss more in that post.

But I think this should work:

list rows.file.link
from "Recipes"
where file.name != "_Recipes TOC"
group by file.path
4 Likes

Nevermind, this isn’t gonna work… file.path includes the note name in the path, not just the parent folder. This can be changed replacing the file.name in the path with nothing replace(file.path, file.name + ".md", ""). But this is only a cosmetic change; you can’t group by this replaced value

@SkepticMystic Thanks so much for giving it a go. I did read your wonderful explanation of group by.; I was hoping there was an example out there that used List rather than Table, thinking that might be why my attempt wasn’t working.

This is a query for your Daily Note template. When you generate a note from the template, the query will show all notes last modified on that daily note’s date.

As a list:

LIST
FROM "" 
WHERE date({{date:YYYY-MM-DD}}T23:59) - file.mtime <= dur(24 hours) and date({{date:YYYY-MM-DD}}T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc

Or as a table:

TABLE file.mtime as Modified
FROM ""
WHERE date({{date:YYYY-MM-DD}}T23:59) - file.mtime <= dur(24 hours) and date({{date:YYYY-MM-DD}}T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc
22 Likes

It looks like some people may have figured this out already (?) but after watching the interview with @EleanorKonik on @nickmilo 's YouTube channel, I figured I’d share how to use Dataview to single out an element a YAML property with multiple elements for those who came here for that reason. Assuming you have made a YAML property with multiple elements, you can use the Dataview command “where contains(property, element)” to isolate one of the elements. For example:

List from ""
WHERE contains(moc, "China")
11 Likes

Is it possible to have file.mtime render as a time only rather than, as now as a date and a time?

for the record… over on Discord @arminta solved this problem…
TABLE (file.mtime.hour + ":" + file.mtime.minute) as Time
That did the trick nicely. Many thanks @arminta

3 Likes

The SORT function in Dataview seems to sort words starting with a capital letter ahead of those in lowercase, e.g. I get this list:
Abenomics
Apple
ability to pay
allocation.
If the sorting was purely alphabetical “Apple” should be at the end of this list.
Do others observe this behaviour?

Excuse me if this has already been answered elsewhere, but I could not find an answer. I would like to extract a year from a full date in a dataview query. The YAML front matter has a ‘Finished’ date (YYYY-MM-DD), and I would like the displayed result in the Field in the table to show the YYYY. Is there a function for this? Also is it possible to run a query to find all the files where the Finished date is YYYY (not full date)?

You can use this snippet to show all files named after the folder they are in:

list
where contains(replace(file.path, file.name + ".md", ""), file.name)

There are some edge cases, but this should show you the file Computers.md in the path Resources/Computers/Computers.md

You can use the .year method on the date to extract only that part :slight_smile:

table Finished.year as Year

You can do the second thing using this:

list
where Finished.year = 2021
2 Likes

That’s terrific, thanks so much! Works a treat. The bit that I am still stuck on is a bigger issue of how to decide what to put into YAML Frontmatter and what to keep outside it. It seems that if something is in front matter it cannot get a back link (e.g. from author page). So I guess that any metadata one wants to be able to back link to from another note should stay out of front matter…?

1 Like

Yes, yaml wikilinks aren’t real links. Aside from returning then in a dataview table, there isn’t a way to click them and go to that link.

---
links: [[Note]]
---

```dataview
table links
```

I don’t need to be able to click them, but I need the backlink to work from another note. For example if I put ‘Author: Some Person’ into the frontmatter, there is no Unlinked mention from the ‘Some Person’ note.

I have been developing a kludge for this that uses the Templater and Dataview plugins.

Let’s say I have a note for the author James Clear (Resources/People/Clear, James.md):

---
first-name: James
last-name: Clear
aliases: ['James Clear']
---

And I also have a note for his book Atomic Habits (Resources/Books/Atomic Habits.md) with the following YAML front matter:

---
author: 'Clear, James'
---

I can use Templater and Dataview to add a dynamically updated list of James Clear’s books to the note on James Clear. The template for such a list, Templates\List of Books by this Author.md, is as follows:

## Books

```dataview
list from "Resources/Books"
where author = "<% tp.file.title %>"
```

After I use Templater to insert the template into Resources/People/Clear, James.md, the source looks like this:

---
first-name: James
last-name: Clear
aliases: ['James Clear']
---

## Books

```dataview
list from "Resources/Books"
where author = "Clear, James"
```

And the preview renders like this:

The link to the note on Atomic Habits is clickable. Unfortunately, Obsidian’s graph does not display the relationship between the two notes.

10 Likes

Interesting, not even an unlinked mention.
Then yes, for now atleast, keeping those links outside the frontmatter is the only option

Apologies if this has been asked a million times.

Is it possible for the following to return the text block, instead of returning a list of pages?

list from #Task

It may not align with the way you’ve structured your tasks, but you can use Task from #Task to return all checkboxes - [ ] .
Otherwise, dataview doesn’t currently allow you to embed the content of a note

It’s probably simple but I could not manage it:
Outgoing links from all notes with a specific #tag

Any ideas?