This cheatsheet provides a handy reference guide for writing queries using Dataview Query Language (DQL) in the dataview plugin for Obsidian.md note-taking app.
I recommend copying this file and including it in your Obsidian vault for easy reference. In this way, you can access the cheatsheet by pulling up the file or searching in your vault for a specific command.
Star and fork this repository to see updates and pull them when more examples are added or the list of commands is expanded.
- Query Commands
- Data Commands
- Metadata Reference
LIST
FROM
<tag-name>
Example
LIST
FROM
#library
TABLE
Title
Author
FROM
#library
Selecting from different sources such as;
FROM #tag
Example
TABLE
file.cday as "Created Date"
FROM
#my-tag
FROM "path/to/file-name"
Example
TABLE
file.cday as "Created Date"
FROM
"TopFolder/SubFolder/my-file-name"
FROM "folder-name"
Example
TABLE
file.cday as "Created Date"
FROM
"my-folder-name"
!#tag-name
Example
TABLE
Title,
Rating,
Seen,
SeenDate as "Seen on"
FROM
#movie AND !#template
The above example will return all notes with a tag #movie
but exclude notes
with a tag #template
. This is handy if you have a note with pre-populated
tags but it's only used as a template so you don't want to see it in your
table view.
FROM #tag AND !"FolderName"
Example
TABLE
Title,
Rating,
Seen,
SeenDate as "Seen on"
FROM
#movie AND !"TemplatesFolder"
By including !"FolderName"
we specify that we do not want to return any
matches if the are located in the specified folder.
You can fine tune query parameters utilizing the AND
and OR
operators
The AND
operator queries notes that meet all criteria included in the query:
TABLE
Title,
Author,
Publication
FROM
"Books" AND "Magazines"
Using in conjunction with exclusion:
TABLE
Title,
Author,
Publication
FROM
"Books" AND "Books/assets"
The OR
operator queries notes that meet any of the provided criteria:
TABLE
Title,
Author,
Publication
FROM
#horror OR #comedy
Using in conjunction with exclusion:
TABLE
Title
Author
Publication
FROM
#horror OR #comedy AND !"Books/assets"
Examples of queries containing WHERE clause.
WHERE
<property-name>
Example
TABLE
file.cday as "Created",
Category
FROM
#books
SORT
file.cday
WHERE
Category
The above example ensures to show only results where the meta-data 'Category' is not empty.
WHERE
<string-property-name> = "my-value"
WHERE
<digit-property-name> = 123
Examples
LIST
WHERE
category = "my-value"
LIST
WHERE
digitProperty = 123
Dataview offers simple ways to sort results. The most simplistic is by some property in ascending (asc) or descending (desc) order:
TABLE
Title,
Author,
Published,
Year
FROM
#library
SORT
Year asc
This should serve well for most use-cases. More complex sorting mechanisms will added here at a later time.
The simplest method is to group by some property included in your frontmatter:
GROUP BY
<property-name>
Group by category in a table:
TABLE
rows.file.name as "File"
WHERE
category
GROUP BY
category
Group by category in a list:
LIST
rows.file.name
WHERE
category = "first-category"
GROUP BY
category
NOTE: When using GROUP BY
, the structure of the results changes. Instead of
directly accessing file.name
, you must use the rows
property to access the
file properties within each group. This is because results are now grouped
into rows based on the GROUP BY
field.
Use FLATTEN
to display multiple properties in a single row
FLATTEN
<property-name>
Code example:
TABLE
Title,
Action
FLATTEN
Action
Result example:
File Name | Created | Action |
---|---|---|
Note 1 | July | Action name 1 |
Note 1 | July | Action name 2 |
Note 2 | August | My Action 123 |
Note 2 | August | Hello World |
You can limit the results in a query:
LIMIT
<numerical-value>
Example:
TABLE
Title,
Rating
WHERE
Rating > 3
LIMIT
10
Dataview provides options on how to display various forms of data. For example, Booleans can be displayed as Yes/No instead of True/False:
CHOICE(<bool-property>, "Yes", "No") as "custom-name"
Example
TABLE
Author as "Author",
choice(read, "Yes", "No") as "Read",
FROM
"Books"
Obsidian allows YAML and JSON for metadata.
JSON
{
"Author": "Author Name",
"Genre": "Fiction",
"DateRead": "2022-06-01",
"Read": false,
"Tags": [
"Mind-blowing",
"Interesting",
"Science"
]
}
YAML
Author: Author Name
Genre: Fiction
DateRead: '2022-06-01'
Read: false
Tags:
- Mind-blowing
- Interesting
- Science