# Obsidian Dataview [repo](https://github.com/blacksmithgu/obsidian-dataview) [docs](https://blacksmithgu.github.io/obsidian-dataview/) [[Obsidian]] Dataview is a plugin that lets you query frontmatter in a [[obsidian-playbook/Using Obsidian/02 Making Notes in Obsidian/Markdown]] file within an Obsidian vault. It effectively turns Markdown files into a database. <iframe width="560" height="315" src="https://www.youtube.com/embed/AhhFLXfldJQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <iframe width="560" height="315" src="https://www.youtube.com/embed/JTObSymEvWA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <iframe width="560" height="315" src="https://www.youtube.com/embed/ccN5vJzXwvo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> ## Dataview Query Language The default way to query using Dataview is through the Dataview Query Language, which is a bit like [[SQL]]. It is triggered using a code block of type `dataview`. For the purposes of showing the code without it rendering, I've commented out the starting and ending backticks for the code block. To make it work, remove the `//` at the beginning and end. ### Return based on file path The query below returns the file link and created date for pages from the folder `Exandria` that also have `Port Damali` in the file path. This holds true for files in `Exandria/Port Damali` but also for those in `Exandria/Menagerie Coast/Port Damali`, for example. > ```dataview > table file.cday as "Date Created" > from "Exandria" > where contains(file.path, "Port Damali") > sort file.name asc > ``` Here's the sample result returned: ![[Dataview table output.png]] ```dataview table file.cday as "Date Created" from "Order of the Wandering Mind" WHERE type = "NPC" or type = "faction" and contains(location,"Luskan") ``` ### Return files in a folder that aren't in a subfolder Given a folder `TTRPGs` that has many folders in it, including `TTRPGs/Temporary White Circle`, return all files except those in `TTRPGs/Temporary White Circle`: > ```dataview > TABLE file.folder as "Folder" from "ttrpgs" > where !contains(file.folder,"Temporary") > ``` ### Return tasks with a tag > ```dataview > TASK from "foldername" > where contains(text,"mytag") > ``` ### Calculate dates Use the metadata somewhere in your note: > startDate:: 2022-07-10 > endDate:: 2022-07-14 Then, use the Dataview query below: > ```dataview > TABLE startDate, endDate, (endDate - startDate) AS Duration FROM "Daily" > WHERE endDate > SORT endDate desc > ``` You'll get the following table: ![[dataview-calculate-dates.png]] ### Display a table with authors and titles, but grouped by author For notes with the field `Author`, use this query: > ```dataview > TABLE rows.title as "Title" from "Readwise/Books" > where Author > Group by Author > ``` For example, if you had two books, *A Spell for Chameleon* and *Source of Magic*, both of which had `Author: Piers Anthony` in the frontmatter, you'd get this result: ![[dataview-group by author.png]] ## Use cases for Dataview - Previous meetings and summaries - Pages where a person is mentioned - TTRPGs - NPCs in a certain place - Locations or shops in a city - Faction members - Magical items, creatures ## Related videos <iframe width="560" height="315" src="https://www.youtube.com/embed/ccN5vJzXwvo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <iframe width="560" height="315" src="https://www.youtube.com/embed/W7kTtn9empU?start=116" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>