Dataview plugin snippet showcase

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, but it won’t allow me to sort based on it:

table regexreplace(, "(?<=\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("" + this.location[0] + "," + this.location[1], "On Google Maps")`

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

`= elink("" + this.location[0] + "," + this.location[1], "On Street View")`

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

`= elink("" + 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.


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:


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

Hope you find them helpful.



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:


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

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:

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

The basic syntax is:

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

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 working. Any suggestions would be gratefully received.

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

Try this one, works for me.

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


Thanks xty,123 I followed your example and tried

table file.mtime
from "journals"
where date(today) - <= dur(7 days)

My journals folder has all my daily notes with filenames like the following 2021 04 24, Sat

The result of the query is Dataview: Query returned 0 results.

It tried renaming one of the files to 2021-04-24 to see if it was a problem with the format of the date string but that didn’t change anything either.

I’ve checked and I’m on the latest version of DataView. Could you tell me the format of your daily note file names and, if it’s different from mine, I’ll see if that makes a difference.