Dataview plugin snippet showcase

I created an issue on GitHub because I thought dataview wouldn’t display all files in my inbox. Turned out it was a feature:

## Did you know …

… that dataview will only list non-empty files?

I had played around with my new Obsidian URI desktop shortcut to create new datetime-stamped note in your Inbox and created lots of empty test files and I use a “Inbox Table-of-Content” note that uses dataview but didn’t show all files:

table file.ctime, file.mtime
from "+Inbox"
where file.name != "+Inbox TOC"
sort file.mtime descending

So now we know! :slight_smile:


EDIT: Turns out that after putting a single character into one of the empty files, it gets listed, but when removing it again (thus emptying the file) it still gets listed. Odd.

EDIT 2: Dataview 0.2.10 didn’t catch all events. This has been fixed in 0.2.13 and I could verify today (with 0.2.14) that the problem has gone.

This also means I was assuming the “empty file feature” (which isn’t true). Thanks @blacksmithgu for fixing it!

FWIW, you can do:

table rows.file.mtime as Modified where file.name = this.file.name group by file.name

No need for the line breaks.

But, dataviews will only work using triple-backtick code fences, so you still need the opening ```dataview (and the closing triple-backticks).

Does any dataview wizard know if you can dynamically subtract dates between fields? I’m trying to create a table of my projects and how long they’ve taken. I’ve got “date-started” and “date-finished” YAML variables for my projects, but I can’t tell if you can create another column that dynamically tells you the duration of the project based on those two fields. I tried defining another variable “length” and subtracting date-started from date-finished, but that doesn’t seem to work.

table status, date-finished, date-started
from ""
where status
sort status desc

Sample note YAML:

---
status: complete
date-started: 2020-06-28
date-finished: 2020-08-29
length: date-finished - date-started
---
1 Like

Hey Janek. You should be able to use a computed field like so:

table (a - b) as NewField

In your example:

table status, date-finished, date-started, (date-finished - date-started) as Length
from ""
where status
sort status desc
4 Likes

4 posts were merged into an existing topic: Dataview, strange display

@SkepticMystic I’m just getting started with Obsidian and came across your amazing plugin - great work. I am interested in a roadmap feature you have mentioned “Hierarchical view”. Not sure what you have in mind but I thought I would describe a need I have in case its relevant. I would like to extract and visualise the hierarchy embedded in a group of notes - specifically each note is an entity (place, person, thing, etc) with a [[link]] to another entity inside it (in my case it is a simple parent-child relationship). I would like to be able to extract all of this and visualise it in a mind map view (similar to the Mind Map plugin). Is that compatible with your thinking?

Hey Simon :slight_smile:
This isn’t my plugin, I’m just a fan!
Regarding your question, I think what you have in mind could work! Checkout @arminta’s reply here, perhaps she can also give you some pointers.

1 Like

@blacksmithgu posted this on GitHub in reply to my question regarding displaying modified time in a note:

This is now possible via inline queries; just put an inline code block in your file:

`= this.file.mtime`

Great!

5 Likes

Also works for other things like …

Last modified: `= this.file.mtime`
Last modified date: `= this.file.mday`
Tags: `= this.file.tags`
Aliases: `= this.file.aliases`

Really great! :grinning:

Now we’ll only have to wait for …

  • date/time string formatting
  • date/time strings being localized into the currently set Obsidian language, not the system language

See Is it possible to specify a format when displaying a date? · Issue #120 · blacksmithgu/obsidian-dataview · GitHub

4 Likes

@SkepticMystic
I watched your video today (thanks for that!). Re your section on “lists”. I could not get any of them to work and I don’t know if perhaps the last couple of updates broke it or if I’m doing something wrong. Presumably I should be able to write list fieldInYaml from "Folder" and get results, right?

With country: UK in my yaml, and list country from "Film/Film Titles" I get no results.

1 Like

Apparently we can’t sort by computed fields?

My note names will always start with a 4 digit year in some folders (ie. 2019.Something) and dataview allows me to correctly extract/display this year from file.name, but it won’t allow me to sort based on it:

```dataview
table regexreplace(file.name, "(?<=\d{4})(.*$)", "") AS Year
FROM "Unsorted/Projects" 
WHERE landmark = "yes"
SORT Year desc
```

The table is there, File/Year columns and results, but sorting it by Year won’t do anything be it ASC/DESC, I can pretty much use sort with any undefined string, same result.

Here are two three other nice ones:

Assuming you use a location: in your front matter (as I do for places of interest)

---
name: Berlin, Weltzeituhr
location: [52.52134162768218, 13.41327381161729]
---

you can create dataview inline external links to Google Maps and Street View like this:

`= elink("https://www.google.com/maps/search/?api=1&query=" + this.location[0] + "," + this.location[1], "On Google Maps")`

Google Maps Search Link created "live" from front matter data, using Dataview!

`= elink("https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + this.location[0] + "," + this.location[1], "On Street View")`

Google Street View Link created "live" from front matter data, using Dataview!

`= elink("https://www.google.com/maps/dir/?api=1&dir_action=navigate&destination=" + this.location[0] + "," + this.location[1], "Google Navigation")`

Google Navigation Link created "live" from front matter data, using Dataview!

These even work in PDFs generated from the note.

12 Likes

wow, that’s crazy!

Hee hee, yes! And useful.

Locate my daughter on the (Obsidian Leaflet) map, have a popup come up, click on the “Route” link, hop over to the map opening in the browser, click “Send to smartphone” … and start driving!

You guessed it—I have a location: front matter entry for People, too. :nerd_face:

5 Likes

Hi friends, I’ve made some posts showing some examples of how I use dataview:

Hope you find them helpful.

23 Likes

Birthday

in front matter and calculated:

---
birthday: 1997-05-17
---

\* `= this.birthday` (`= "Age " + (date(today) - this.birthday).years`)

For a little fun, leave out the .years part … :grin:

4 Likes

Weird, it also doesn’t work for me. Maybe that isn’t supported anymore

How can I get table view to display the date in the same format I use in the YAML header (YYYY-MM)? I tried wrapping it in quotes but that doesn’t make it a string. I tried the concatenation trick and that gets me closer, but it doesn’t zero-pad the month.

1 Like

Amazing, thank you!

There’s a feature request on Github that you might like to support: Is it possible to specify a format when displaying a date? · Issue #120 · blacksmithgu/obsidian-dataview · GitHub

1 Like