avatarEsteban Thilliez

Summary

Dataview is an Obsidian plugin that transforms a vault into a database, allowing users to query and display metadata from their notes.

Abstract

Dataview is a powerful Obsidian plugin that enables users to treat their notes as documents in a database. By using Dataview, users can add metadata to their notes and then query that metadata using Dataview Query Language (DQL), inline expressions, or DataviewJS. DQL is a pipeline-based language similar to SQL, and it allows users to display their data in tables, lists, or tasks. Users can also sort and limit their data using DQL commands. Dataview provides a way to add more functionality to Obsidian and turn a vault into a powerful tool for managing information.

Opinions

  • Dataview is a plugin that can turn an Obsidian vault into a powerful tool for managing information.
  • Dataview allows users to add metadata to their notes and then query that metadata using various methods.
  • DQL is a powerful language for querying data in Dataview, and it allows users to display their data in various formats.
  • Dataview provides a way to add more functionality to Obsidian and make it more useful for managing information.
  • Dataview is a complex tool that requires some learning to use effectively, but it can be very powerful once mastered.
  • Dataview can be used to track habits in daily notes and display that information in a useful way.
  • Dataview can be used to group multiple notes into one entry in a table, making it easier to manage large amounts of information.

Obsidian Dataview: Build your Vault as a Database

Dataview is an Obsidian plugin you can use to transform your vault into a database you can query from.

A Dataview example

If you want to use Obsidian for more than just note taking, you’ll probably have to install some plugins. Indeed, some plugins can turn your vault into something very powerful. Dataview is one of these.

What is Dataview

Dataview is a plugin allowing you to transform your vault into a Database. It means you can treat your notes as if they were documents, and query them in a note.

For example, imagine you use daily notes. All these notes are stored somewhere, and there is no way to have an overview of all of them except through the file explorer, but it’s not really an overview, as you will just see the file names. If you track your habits in your daily notes, you can’t see them this way.

In this case, you can use Dataview. You just have to create a note called for example “Daily notes overview” and put in it a Dataview query. In the query, you tell Dataview the folder containing the daily notes, the metadata you want to see, if you want to see the files sorted, etc… and it will show you something like this:

How to use Dataview

Metadata

Dataview allows you to pull metadata from your vault. But how to add metadata in notes?

  • YAML frontmatter: Dataview can pull all the YAML metadata in your vault.
An example for tracking habits in daily notes through YAML
  • Dataview syntax: Dataview provides a Key:: Value syntax for referencing data elsewhere than in YAML. The above implementation becomes:
cold-shower:: ✅
workout:: ➖
anki:: ✅

Queries

Once you have some metadata in your vault, you can consider querying. If you don’t want to use metadata, you can still query the file names, but nothing more.

You have 3 ways of querying data:

  • Dataview Query Language (DQL): A pipeline-based language, similar to SQL. Can be used for basic cases. Here is an example for tracking habits in daily notes:
```dataview
TABLE WITHOUT ID
 link(file.name) as "Day",
 row["cold-shower"] AS "🚿",
 row["workout"] AS "🏃‍♂️",
 anki AS "🎴",
 FROM "600 Periodic/610 Daily" 
 SORT file.name DESC
 LIMIT 30
 WHERE file.name != "610 Daily"
```
  • Inline Expressions: DQL provides you with some expressions you can embed directly into your notes. For example, if in a note I type `= lower("YES")` , it will be displayed as yes in view mode.
  • DataviewJS: Dataview provides you with a JavaScript API you can use to query more complex things. Here is an example from the official documentation:
```dataviewjs
dv.taskList(dv.pages().file.tasks.where(t => !t.completed));
```

I will talk about the DQL syntax now.

DQL

Here is the DQL syntax from the official documentation:

```dataview TABLE|LIST|TASK <field> [AS "Column Name"], <field>, ..., <field> FROM <source> WHERE <expression> SORT <expression> [ASC/DESC] ... other data commands ```

Only the TABLE/LIST/TASK statement is required.

When creating a DQL query, you have to choose a way of displaying your data first. You can choose between TABLE , LIST or TASK .

  • TABLE: the basic way of displaying data. One file for one row, and one metadata for one column.
  • LIST: a list of pages matching the query. Unlike the TABLE view, you can output only one value for each page.
  • TASK: a list of tasks whose pages match the given query.

You can provide an additional argument that is WITHOUT ID . It hides the file names in the view.

Then, you have to provide the output data:

TABLE WITHOUT ID
link(file.name) as "Day",
row["cold-shower"] AS "🚿",
row["workout"] AS "🏃‍♂️",
anki AS "🎴",

For the output data, and even everywhere in the query, you can use expressions (such as link , row , …) if you want.

AS is used to tell Dataview how to display your data.

Then, you can use FROM to tell Dataview where it should look for information. The arguments can be tags or paths to folders. You can also use logical expressions such as OR.

FROM #periodic-notes/daily
...
FROM "600 Periodic/610 Daily"
...
FROM #periodic-notes/daily OR #periodic-notes/weekly

You can also sort your data using SORT .

SORT file.name DESC
...
SORT file.name ASC

You can use WHERE to add conditions to your query.

```dataview
TABLE WITHOUT ID
 link(file.name) as "Day",
 row["cold-shower"] AS "🚿",
 row["workout"] AS "🏃‍♂️",
 anki AS "🎴",
 FROM "600 Periodic/610 Daily" 
 WHERE file.name != "610 Daily"
```

Above, I used WHERE to tell Dataview I don’t want it to add my note named 610 Daily to the table. It’s because it’s my daily notes overview.

Then, GROUP BY can be used if you want to group multiple notes into one entry in a table.

GROUP BY day
...
GROUP BY day as Day

If you don’t want too much data to be on screen, you can limit your data using LIMIT .

LIMIT 30
...
LIMIT 5

Finally, commands are processed in the order they were written. So, the following sorts the results after they’ve been limited:

LIMIT 30
SORT day ASCENDING

Final note

There are so many things you can do with Dataview. I don’t want this story to be too complex or too boring, so I won’t talk about the other Dataview features such as DataviewJS or Expressions. If you want a complete reference, you can find everything here: Dataview reference.

Find all my Obsidian-related stuff here: Use Obsidian like a Pro

To explore more of my self-improvement stories, click here!

If you liked the story, don’t forget to clap and maybe follow me if you want to explore more of my content :)

You can also subscribe to me via email to be notified every time I publish a new story, just click here!

If you’re not subscribed to medium yet and wish to support me or get access to all my stories, you can use my link:

Obsidian
Notes
Personal Development
Personal Growth
Knowledge
Recommended from ReadMedium