Dataview plugin snippet showcase

I have just discovered this plugin and have been playing with it to create a kind of TOC for my literature notes. It’s awesome.

Currently, my table looks like the picture, and my query is

TABLE author as Author, title as Title, tags as Topic
FROM ""
WHERE contains(file.name, "@") and area = "medieval" and type = "secondary"
sort author asc

(all my lit notes start with “@” in the filename).

I would like to do the following but not sure if it’s possible – does anyone know?

The first, “File” column of the table with the file names is not very informative for my purposes (I name the lit notes by the appropriate bibtex citekey). Is it possible to not have that column at all, and link to the files by one of the other columns, let say, by the title? – This is mostly a cosmetic issue, but then the table would have more space for the other things that are important.

Again, this is a great plugin, I have been using it a lot for all kinds of tables and lists :slight_smile:

3 Likes

For removing the first file column, you can add this to your css snippets,

.dataview.table-view-table th:first-of-type,
.dataview.table-view-table td:first-of-type{
    display: none;
}

As to having another column link to the file, I don’t know a way yet. The only thing that returns a link from the query is file.link but that still shows the file name which you don’t want.

2 Likes

Has anyone here figured out how to calculate days remaining for an event? I’m trying to have days remaining for a person’s birthday in their respective note and have birthday: 1985-03-03 in my YAML.

I can do = (date(today) - this.birthday) to get the age or = (date(today) - this.birthday).years to get the age in years. I can’t seem to do a countdown till their birthday if it is later this year, or if it’s passed already, then next year.

What I’ve tried so far is to separate the month and date from the calculated full age and for the months I can just do a simple = 12-((date(today) - this.birthday)).months+" months" but how do I do the same for the days since I cannot be sure of the length of a month?

Thank you @Rishi , this is super helpful!

Can’t you do something simpler like this:

table from "People"
where birthday < date(today) + dur(2 months)

Assuming you store birthday like this: birthday: 2021-04-29

1 Like

Be careful with that CSS, because it brute-force-removes the first column of a table.

But what if you had a table like this:

table rows.birthday as Birthday, link(rows.file.name) as Name
from "People/Friends & Family"
group by file.name

The “Birthday” column would be gone!

For @atiz’ use case, it would probably be best to ask the developer to introduce an optional 2nd argument to the link() function, much like he already has for elink().

So one could use something like

link(file.name, author)

in the table.

4 Likes

@SkepticMystic This wouldn’t work for “real” birthdays (with year)—they’d all be in the past.

Otherwise I wouldn’t have had to come up with crazy calculations like in Upcoming Birthdays.

What Dataview lacks is “real” SQL syntax and/or Javascript access (we could use moment.js then, or built-in SQL date calculations).

1 Like

Thanks for calling me out on the quick-and-dirty solution!

There is already an issue on github regarding this with one potential solution(with caveats) using group by as well.

Also the developer has announced that this will be introduced in the future. Until then, I guess the best option is to combine my CSS code with cssclass so that the code doesn’t apply to all notes.

2 Likes

Cheers for taking it graciously :slight_smile:

It’s actually from my own experience: Quick-n-dirty solutions tend to stick, get used and buried in large vaults … and suddenly things don’t work correctly anymore and it’s hard to find the fault.

3 Likes

Can’t argue with that!

Also, kudos on that interesting query for the birthdays above! Having spent the better half of my day today trying (and failing) to get a countdown to an event (birthday co-incidentally), I hit some of the same walls as you with not being able to calculate with dates without the year and having the year makes everything in the past.

Yeah, we should really have date calculations! :wink:

See also:

Thanks for the links. I had already seen all of them earlier today when creating my own issues there. I guess we just have to be patient for now and keep thinking of all the possibilities this enables now in our vaults. :metal:

2 Likes

Ahh I get you! Yes, this does then require “crazy” calculations :yum:

For a simpler version of the birthday list, add the following to your daily note template. Adjust for date formatting and additional data to include

### Birthdays Today
```dataview
table phone as Phone, email as Email
from ""
where contains(birthday, "<% tp.date.now("MM.DD", 0, tp.file.title, "YYYY.MM.DD") %>")
```

Note: @Moonbase59’s code is much more robust and will show upcoming birthdays. A much better solution than mine. The above will only show today’s birthdays. I just opted for this because I couldn’t get his working and this is good enough until we get some date calculations, as @Moonbase59 linked above.

Thanks @Moonbase59 for both!

hello, first of all, I’m a beginner at programming language.
I’m trying to using dataview feature to improve my language learning process. I have an idea about how i will use dataview, but i cant make the query and the other stuff that need to do.

basically, i simply add some metadata on each new words that I want to remember. Then i can easily see them on my dataview based on the metadata query. Im sorry if it a little confusing, but i have some sketch to it.!

IMG_0284|500x500

im planning to build like this one, but i dont know where to start hehe. anyway, is it possible? Thank you!

That sounds pretty straightforward. Start with this,

```dataview
TABLE Type, Mean, Relate
FROM ""
```
1 Like

The result (Date & Time) is in my notes always on line below the prefix.
So:
Line 1 Last Modified
Line 2 2. May 2021, 16.30

Do you have any idea how to get both in one line?

Hi,

Before my questions, just two notes: 1) I’m a relative newbie in Obsidian and an absolute newbie in Dataview plugin; 2) I’m not a programmer or similar and my knowledge of code is almost zero.
Having said that (just to excuse my ignorance), I start with the compliment: this plugin seems a huge tool to build great databases, with potential to definitively replace one of the main features that retains some users in Notion.

Now my case. For research purposes, I intend to create a database with some historical facts (a kind of complete biography of a historian). For this, for each ‘historical fact’ I create a .md file with some notes, information and links (files indexed in Devonthink and using the advantages of Devonthink’s x-callback-url to create links between different files/formats).
Now, with the ‘dataview’, I intend to use this tool to create a kind of landing page that serves simultaneously as a ‘timeline’ (creating a table, ordered chronologically, with the information of the fields introduced in the YAML metadata).
Obviously, one of the main fields concerns dates. And my problems / limitations start here.
Here is my query:

```dataview
table (dataInicio.year + "/" + dataInicio.month) as Inicio, (dataFim.year + "/" + dataFim.month) as Fim, ((dataInicio - date(1933-11-03)).year + "/" + (dataFim - date(1933-11-03)).year) as Idade, grupo, subGrupo as sub-grupo, subEventos as sub-eventos, file.tags as tags, link
where file.name != this.file.name
sort dataInicio

My problems are related to these three fields (sorry for portuguese language) : dataInicio (Startdate); dataFim (Enddate); Idade (age).

  1. The first issue is related to the date format: whichever format is used in the metadata fields (YYYY-MM or YYYY-MM-DD), the table shows the format day of the week, day/month/year. The historical facts have very different dates: precise dates (YYYY-MM-DD), others less (YYYY-MM) and others very vague (YYYY - in these cases I have to deduct one month). The day of the week information is totally unnecessary for this type of database. To remove this information I use the code (dataInicio.year + "/" + dataInicio.month) to get something like 1953/10. If I add dataInicio.day I have a problem: in the ‘historical facts’ with the format YYYY-MM, the result add the first day of the month (YYYY-MM-1).
  1. With the previous solution, if the dataFim (endDate) field is empty, the table presents the result “null/null” and not the “-” as defined in dataview settings for nulls results. [All the ‘historical facts’ have a start date (more or less accurate) but some have not end date.]
  2. The field Idade (age) is intended to show the age of the historian at the beginning and ending (if applied) of each ‘historical fact’. For that I use this: ((dataInicio - date(1933-11-03)).year + "/" + (dataFim - date(1933-11-03)).year) as Idade (for results as “23/32”). When I have both dates (start and end) everything works correctly, but if the end date is empty the result is “null/null” (does not even display the first value, related to age at the start date). The only way to formula works seems to be the introducing of an end date equal to the start date!

Well, that’s enough for now. Does anyone have any suggestions for overcoming these limitations or for now these limitations are intrinsic to the plugin?

Thanks.

One suggestion: considering the idea of a ‘timeline’, it would be truly incredible if there was a possibility to extend this plugin - using the results of the query - to build a mermaid gantt diagram.

1 Like

The inability to play with date formats is so far a limitation of the plugin requiring many complex workarounds, much like your own getting the year and month separately and then concatenating them.

If I were doing something like this, I’d probably try to have the age calculated as a field in the metadata already instead of calculating here in Dataview. Since the benefit of historical data is that the dates rarely ever change, you can calculate it once and save it so future access doesn’t require calculations. You might want to check out the Templater plugin which also supports YAML fields. Using that, you could generate an Age field in your files using the start/end dates from the same file and save the calculated field. Dataview will need to just display them. Since Templater has much better support for date formats, you’d find it much easy to do it there.

I looked in the documentation and through this thread and surely I must have skipped over it somewhere - but how can I display just incomplete tasks? Is incomplete a ‘where’ condition? (cause I tried that, and it didn’t work)

task from "" where file.name !="todo" and....?

Ah, I found my answer on GitHub in the “issues”:
“Should work as part of the task improvements which let you do full queries over tasks (including completed, contents, child tasks, the works).” Should be availabe in an “Upcoming major release (0.3.0), probably after a bugfix release coming up.”

1 Like