Use Obsidian Dataview Plugin to Automate Our Vault

Why Problem Does Obsidian Dataview Solve for Us?

Before going over how to use Obsidian Dataview, let’s step back to the first principle — what kind of important problems does Dataview solve for us?

Suppose we have accumulated a bunch of notes for the books we read, how could we visualize them in a table view with meaningful table headers such as author, cover, status, rating, etc? Especially if you come from Notion, you might miss the table view. The good news is we could achieve that by using Dataview plugin in Obsidian. Dataview not only displays our notes in the forms of tables, lists, etc. with or without filtering but also makes our life much easier by automatically importing the updated notes.

In this article, I will walk you through what is Dataview, how to show our notes in forms of views like tables, lists, etc., how to query our notes, and lastly, I will also provide personal use cases.

What Is Dataview?

Let’s have a brief knowledge about Dataview based on its official documentation.

Dataview is one of the most powerful plugins in Obsidian. It allows us to create tables, lists, tasks, and calendars to manage our notes, track our tasks, etc. but it can get overwhelming quickly from the very beginning when we read the definition of Dataview: According to the definition of Dataview the author:

You can associate data (like tags, dates, snippets, numbers, and so on) with your markdown pages, and then query (like a filter, sort, or transform) this data. — obsidian-dataview doc

Don’t worry if you don’t quite understand what that means. Let’s break down the concept into three main components:

  • Annotation
  • Query

But I would like to add another component which is View. Now let’s dive deep into each of the components.

  • View
  • Annotation
  • Query

Install and Enable Dataview Plugin

Core Concept 1: View Data Using Obsidian Dataview

Dataview provides four views:

LIST|TABLE|TASK|CALENDAR

Let’s jump into the Dataview code to demonstrate these views for the notes of our Vault.

Execution steps:

  • Open or create a note in Obsidian
  • Type the Dataview code block
```dataview

```
  • Try out the views of the list (LIST), table (TABLE), and task (TASK)
  • See the outputs in preview mode (Cmd + E).

TABLE

```dataview
TABLE
```

LIST

```dataview
LIST
```

TASK

```dataview
TASK
```
GIF by Amy Li

To make the CALENDAR work, we need to add more arguments.

CALENDAR

We need to add an argument, such as file.mfile or file.cfile, to make the calendar work.

```dataview
CALENDAR file.mfile | file.cfile
```
GIF by Amy Li

We cannot ignore the automation process for Dataview. Whenever we create a new file or modify an old file, they will be immediately automatically reflected in our Dataview outputs. This is an aspect I admire Dataview so much. It’s designed to automate our notes systematically.

Core Concept 2: Annotate Data Using Obsidian Dataview

You might notice from the above examples that the table looks very much like a list when we don’t have the table header as in above. This section is showing you how to display the customized table header for us. To have the table header, we first need to add metadata to our notes, which is the so-called Annotation for Dataview plugin. YAML is the most recommended way of adding metadata to Obsidian notes, if you don’t know how to use YAML, you could check out my previous article

How to Create and Use Tags in Obsidian YAML

Add metadata of tags to Obsidian notes using YAML front matter

But don’t worry, even if you never used YAML before, you can follow because I will explain the YAML code here as well.

Three requirements for a valid YAML code in Obsidian:

  • Add three dashes at the start/end to form a YAML code block
  • Must be placed at the top of the file
  • Adding spacing between the colon and the value
---
alias: "document"
last-reviewed: 2021-08-17
thoughts:
rating: 8
reviewable: false
---

Now we know how to add metadata to our notes using YAML, let’s see it in action.

Let’s say I have some notes in my vault with the metadata of author, status, and category, and now I write Dataview code to display them as a table header.

```data view
table author as "Author", status, category
table author as "Author", status as "Stage"
```

The metadata defined in any of the book notes:

---
tags:
- booknote/action
alias: Atomic Habits
Author: James Clear
year: 2018
cover: "![[Atomic Habits.jpeg]]"
category: self-development
rating: Lifechanging
status: " #booknote/action"
ISBN:
---

Throughout this article, I will repeatedly demonstrate Dataview Query Language based on these metadata.

Core Concept 3: Query Data Using Obsidian Dataview

We have learned how to show our notes in different views, but in many times, we only want to display some selected notes rather than all the notes in our Vault. For example, I just want to have a table view of all the notes about my reading, or the notes belonging to a specific project I’m working on.

Query — FROM

Structure: FROM <source>

Let’s learn two types of sources — tag and folder.

We could filter our notes by the tag:

```data view
TABLE cover, author, rating, status
FROM tag_name
```

or by a folder name:

```dataview
TABLE cover, author, rating, status
FROM "foldername"
```

or combinations such as FROM tag_name2 or/and tag_name2 , FROM tag_name or/and folder_name , etc.

GIF by Amy Li

Query — WHERE

Sometimes FROM is enough to achieve what you need, but in some situations, you might want to filter your query further. Then WHERE comes to play.

Here are some examples:

  • Show the file named “Atomic Habits”.
```dataview 
table cover, author, rating, status
WHERE file.name = "Atomic Habits"
```
Screenshot by Amy Li
  • Display the files which contain a status of #booknote/action
```dataview
table cover, author, rating, status
WHERE contains(status, "#booknote/action")
```
Screenshot by Amy Li
  • List the files which don’t have any tags:
```dataview
LIST
WHERE length(file.tags) = 0
```
GIF by Amy Li

Query — SORT

sort in ascendant or descendant order.

List all of the files in the booknotes folder or with the tag #booknote, sorted by the last time we modified the file:


```dataview
TABLE file.mtime AS “Last Modified”
FROM #booknote
SORT file.mtime DESC|ASC
SORT file.size desc
```
GIF by Amy Li

Query — GROUP BY

```dataview
list rows.file.link
from #booknote
group by status
```
Screenshot by Amy Li

Two Huge Benefits of Using Obsidian Dataview

Benefit 1: Easy to share the code with others.

As a programmer, I enjoy writing code to achieve something. Even you’re if not a programmer, you could also quickly learn how to tell the code what you want to achieve by following the Dataview doc. As a community plugin, it’s so kind for the author to design, build and document the application so well.

Benefit 2: Automatically imports the updates.

Any updates will be automatically added to our Dataview. For example, when we create a new note, it will be automatically picked up by Dataview.

Wrap Up

This article has covered the basic concept of Dataview, how to display our notes in the forms of tables, lists, etc., and how to query our notes to filter through our notes to meet our needs.

Check out more FREE tutorials on our website.

Index