How to get started with Obsidian Dataview and DataviewJS

In a previous OS TechBlog post we introduced Obsidian as a note-taking app. Here I will take you to the next level of organising your notes, with the Dataview plugin for Obsidian. This is one of the ultimate tools for linking your thinking and pulling it together in different ways.
If you haven’t read Obsession with Obsidian I can highly recommend it as a great introduction to Obsidian.
Get Started Simply
To try out these examples and tips you will need to download and install Obsidian and then install the Dataview plugin, both of which are free.
If you haven’t installed a plugin in Obsidian yet follow these steps after installing and opening Obsidian:
1. Click the cog (settings icon) in the bottom left.
2. Click Community Plugins, in the window that opens, and turn off safe mode if it is on.
3. Click the browse button and search for ‘dataview’ in the search box.
4. Click on the Dataview plugin, then the Install button and finally the Enable button.
Dataview, in the words of its creator, allows you to
“Treat your Obsidian Vault as a database which you can query from”
With Obsidian built on top of a graph database, this makes total sense.
Here are a few examples of how we can query our Obsidian notes using the Dataview Query Language (note: I will expand on how you can use JavaScript later in this article):
Using Built-In Obsidian Metadata
The following will list the files in a folder called technology, along with the file creation time and date, and order them by creation time in descending order.
```dataview
table file.ctime as "Created Time"
from "tech"
sort file.ctime desc
```
You can list all the files in your Obsidian vault very simply:
```dataview
list
```
Using tags and your own meta-data
With Obsidian you can add tags to a file, either by typing them with a #, e.g. #myTag or by including it in a front matter section using YAML (see below). This is also where you can include your own custom metadata.
Example YAML
---
tags: ['myTag', 'AnotherTag']
type: 'review'
rating: 4
---So if I have some reviews I have written I can collect them together in a table:
```dataview
table rating as "Rating", dateRated as "Date Rated"
from "music"
where type = "review"
sort rating desc
```
As you can see you can get very clever with how you add and use your own metadata.
Tasks
If you have created tasks in your Obsidian notes then Dataview can collect them together in clever ways.
Perhaps you want to create a task dashboard. Here is a really simple example of how to create two separate lists of tasks from files with different tags, and you can check off or un-check the tasks in the list too:
```dataview
task
from #ukulele
```
---
```dataview
task
from #research
```
A Step Further: DataviewJS
For those of you wanting more here is a quick introduction to using DataviewJS. It is similar to Dataview but using JavaScript to access the API that Dataview exposes.
Using JavaScript we can refine the task list further, by eliminating tasks we have already checked, and even showing all our checked tasks together:
```dataviewjs
dv.header(2, 'Ukulele Tasks');
dv.taskList(dv.pages('#ukulele').file.tasks
.where(t => !t.completed));
```
```dataviewjs
dv.header(2, 'Research Tasks');
dv.taskList(dv.pages('#research').file.tasks
.where(t => !t.completed));
```
```dataviewjs
dv.header(2, 'All Completed Tasks');
dv.taskList(dv.pages().file.tasks.where(t => t.completed));
```
But my favourite way of using Dataview is to create whole notes from metadata, essentially creating a dashboard or user interface to my stored data. More to come in another article, but below is an example for the curious.
Note structure for a training provider
The content of this note is created completely by Dataview, using custom metadata in YAML:
---
type: 'training provider'
tags: ['training', 'provider']
website: 'https://www.pluralsight.com'
title: 'Pluralsight'
---```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity
dv.header(1, pg.title); // print the page title from YAML as H1
dv.header(2, 'Website'); // print 'Website' as an H2
dv.paragraph(pg.website) // print website url from YAML in a paragraph
dv.header(2, 'Courses Taken:'); // print 'Courses Taken' as an H2
dv.list(dv.pages('#training').where(p => p.provider && p.provider.contains(pg.title)).file.link);
```

And structure for notes on a course from a training provider
Again, the content is displayed completely by Dataview:
---
type: 'training notes'
tags: ['training', 'notes']
courseTitle: 'How to Be a Great Mentor: Get More out of Mentoring'
link: 'https://app.pluralsight.com/library/courses/how-to-be-great-mentor'
provider: 'Pluralsight'
---```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity
dv.header(1, pg.courseTitle); // print the course title from YAML as H1
dv.header(2, 'Link'); // print 'Link' as an H2
dv.paragraph(pg.link) // print website url from YAML in a paragraph
```## Notes
- my notes
- in this
- section---```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity
dv.header(2, 'Other ' + pg.provider + ' Courses Taken:'); // print 'Other <provider> Courses Taken' as an H2
dv.list(dv.pages('#training').where(p => p.provider && p.provider.contains(pg.provider) && p.file.name != pg.file.name).file.link); // print other courses by the same provider, excluding the current page
```

What’s next?
I hope you can now see just some of the potential for using Dataview with Obsidian to harness the data in the underlying Obsidian graph database.
Have a go and implementing the above, if you haven’t already, and experiment with your own use cases.
In a later post, we will look in more depth at Dataview and DataviewJS and some more advanced examples.
Here are some useful links to the Dataview Documentation, which contain more examples:









