Dataview plugin snippet showcase

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

Thanks xty,123 I followed your example and tried

table file.mtime
from "journals"
where date(today) - file.day <= 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.

Thanks,
David

Try this for a bit of troubleshooting:

list
from "journals"
where contains(file, "day")

If the file shows up then the .day field is populated, meaning it recognizes the date in the file name.

If the file does not show up it means dataview does not recognize a date in the file name.

Could you share the code behind all of this (placing the dots on the maps etc)? It’s amazing!

That produced no results so clearly my naming convention for daily files isn’t recognised. I have tried creating files with various date formats for the filename but none seem to work. Weird !

Does anyone else suddenly have a lot of extra empty space between rows in a dataview table … ? Everything is up 2 date, without a custom skin or snippets.

1 Like

Well … not suddenly … I have always had way too much space bewteen rows in a table. I mostly use lists because of it.

So, I’m having sooo much trouble with contains, can somebody help please…
in my notes I have…
## Metadata Authors:: [[Justin Erik Halldór Smith]] ItemType:: [[Blog post]]
and I’m tring to get a dataview of those blog posts, or websites, or magazines, etc. I have this dataview
TABLE Title, ItemType, Date from "Zotero mdNotes" WHERE ItemType SORT desc
which gives me this…


But I cannot for the life of me (been at it all day today) get it to produce a table of just the blog posts.

Any ideas?

I’m a huge fan of Conan the Barbarian comics, so I’ve started cataloging them. I’ve barely made a dent - I have more than 1,100 more to process. Plus I’m building a compendium of recurring characters, important places, and notable objects. It’s a big project! But I’m re-reading each issue as I catalog them, so I’m having lots of fun :nerd_face:

14 Likes

Hi,
I’ve just started playing around with Dataview and I am having problems with thousands separators (comma’s) in numbers.
I have in-line numbers like 1,234 which are read as two separate numbers 1 and 234.
If I make it 1234 it’s all good but it’s hard to read with large numbers. The only way I’ve found to preserve them is using quotes but then the output is not a number and I can’t do any calculations with it. Even if I could format the output correctly that would be a win.

1 Like

Sure. Basically, I have a folder People/Friends & Family where I put my TOC (Table of Contents) file and the single people’s notes.

In my “TOC” note, I have a leaflet map, centered on a theoretical “midpoint” of Germany, so I get a nice view, plus a list of people:

---
tags: friends, family
---

[[+Home]]

---

# Friends & Family TOC
This is the Table of Contents of your friends & family.

​```leaflet
height: 500px
lat: 51.133333
long: 10.416667
minZoom: 1
maxZoom: 18
defaultZoom: 5
​```

The list is sorted by last modified time, newest at top.

​```dataview
table birthday as "Birthday", file.ctime as Created, file.mtime as "Last modified"
from "People/Friends & Family"
where file.name != this.file.name
sort file.mtime descending
​```

You can then create some different markers in the settings of Obsidian leaflet (check Docs): I made “Friends”, “Family” and “Location” under Additional Map Markers.

Then simply zoom into the map, right-click and create new markers, specifying the map marker type and the linked note, or (quite cumbersome still)

  • export the current leaflet data csv,
  • add entries manually (people notes referred to must already exist), and
  • import the CSV again.

The CSV basically looks like this (check docs):

People/Friends & Family/+Friends & Family TOC.md/real,Family,51.133333,10.416667,Matthias C. Hormann,,
People/Friends & Family/+Friends & Family TOC.md/real,Friends,51.133333,10.416667,Friend 1,,
People/Friends & Family/+Friends & Family TOC.md/real,Location,52.52134162768218,13.41327381161729,Berlin Weltzeituhr,,3f4981d8-1615-4905-9cc4-e4df122215be

If you leave out the GUID in the last column, it gets created by Leaflet automatically. The locations given here are fake values, of course (except for the “Weltzeituhr” in Berlin).

You may need to refresh the note containing the map after import, to make it show all markers.

My “people” notes are really simple and just have the “calculated” links at top:

---
location: [51.133333,10.416667]
birthday: 1970-07-11
tags: friends
---

[[+Friends & Family TOC]]

`= elink("https://www.google.com/maps/search/?api=1&query=" + this.location[0] + "," + this.location[1], "Google Maps")` `= elink("https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + this.location[0] + "," + this.location[1], "Street View")` `= elink("https://www.google.com/maps/dir/?api=1&dir_action=navigate&destination=" + this.location[0] + "," + this.location[1], "Route")`

---

# Friend 1
\* `= this.birthday` (`= (date(today) - this.birthday).years + " Jahre"`)

This will later have the correct links and look like this:

Clicking on the “Route” link, for instance, then opens the Google Route Planner in your browser (from which you could click “Send to my smartphone” and get instant navigation):

Hope that helps!

7 Likes

As of version 0.2.17 the tables are back to normal for me. At version 0.2.14 it was “bugged” and a lot of extra space was between rows in a table.

I like your use of Birthdays. Now I want to add a dataview of upcoming dates on my daily notes. No clue how to write that though. Any dataview ninjas have any ideas?

Before I post as a bug in Github, can someone do a quick test?
in frontmatter I have
- - -
datecreated: 2021-04-27
- - -

In a dataview rule I’m trying to use that field: I’ve tried
list “Film/Film Titles”
where datecreated=2021-04-27
where datecreated=“2021-04-27”
where contains(datecreated, “2021-04-27”)
where contains(datecreated, 2021-04-27)

Keep getting 0 results.

Well, it’s possible but really clumsy due to the restricted syntax of Dataview. I wish we had “real” SQL syntax and/or JS.

Let’s say we want a “upcoming birthdays” table for the next two months from now. Crossing year boundaries must be possible (i.e., if you are in December, you also want the January birthdays), and the list sorted. Also, you want to show what birthday it will be.

Warning: This is not elegant, rather clumsy, relies on numerical computations and lots of repeating calculations! This isn’t production-quality code, but just a proof of concept.

You will have to change the desired duration to show in three places in the dataview code block (look for dur(2 months)).

### Upcoming Birthdays

Here are the upcoming birthdays for the next 2 months (until `=date(today) + dur(2 months)`).
table birthday as "Birthday", choice(
date(today).month*100+date(today).day = birthday.month*100+birthday.day,(date(today)-birthday).year,(date(today)-birthday).year+1) as Turns
from "People/Friends & Family"
where file.name != this.file.name and
choice(date(today).month*100+date(today).day > birthday.month*100+birthday.day,
(date(today).year+1)*10000 + birthday.month*100 + birthday.day,
date(today).year*10000 + birthday.month*100 + birthday.day) <= (date(today) + dur(2 months)).year*10000+(date(today) + dur(2 months)).month*100+(date(today) + dur(2 months)).day
sort choice(
date(today).month*100+date(today).day > birthday.month*100+birthday.day,
(date(today).year+1)*10000 + birthday.month*100 + birthday.day,
date(today).year*10000 + birthday.month*100 + birthday.day)

It will look like this:

Have fun! (And hope for a combined SQL and Javascript engine.)

If anyone knows how to simplify this horrible code (and retain full functionality), please let us know!

5 Likes