Dataview plugin snippet showcase

@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

Hi all, not a programmer at all and hoping someone can help.

Wanting to know if it’s possible to take a number of files with the following in YAML:

Name: [Bill Smith]
Reportsto: [Jane Doe]

and build an outline view eg.

Jane Doe
  - Bill Smith
  - Ian Holiday
    - John Tan
etc

Possible? Thanks.

1 Like

How did you get the table to alternate background colors on each row here? is that a css snippet too?

FYI @blacksmithgu was kind enough to implement this feature request I submitted and it was quietly slipped into the release notes recently. :slight_smile:

Say you have files with a field named foo.

Some have foo: A and others have foo: B.

You can now do:

table choice(foo = "A", "Aaaaylmao", "Booo") as myFieldName

And you will get exactly what you expect.

You can also NEST CHOICES:

table 
	choice(foo = "A", 
		   "Aaaaylmao",
		   choice(foo = "B",
		   		  "Booooo",
				  "Yay")) as blah
sort blah asc

The basic syntax is:

result = choice(boolean test, true value, false value)
11 Likes

Suddenly all my dataview codeblocks are showing zero results. I have not changed anything. What has happened? any changes in code?
Does anyone have the same problem?

P.S: I had to change the code and go to review mode and correct it again to get the results again. That was a new bug, I really wish there was a forced refresh button in this plugin.

I had the same problem. It started when Obsidian updated and started indexing note content. I gave it a while, restarted Obsidian, and my dataview blocks worked fine

1 Like

The unusual thing was that it didn’t go away even after many restarts. Also I notices that I had to make the code wrong, not just change it, to get back my results. They were always there and I was not messing with to need a update.

I would like to search in my daily note files but only for the last 7 days. I can’t use the created or modified time because some of my daily files are created in advance. The format of the file names is YYYY MM DD, ddd e.g. 2021 04 24, Sat.

I can’t seem to get anything using file.day working. Any suggestions would be gratefully received.

table file.ctime as Created, file.mtime as Modified
from "your daily notes folder"
where date(today) - file.day <= dur(7 days)

Try this one, file.day works for me.

I wrote up an example for using dataview to process media: Dataview for reviewing and processing media

2 Likes