Obsidian-Dataview
This is my notes of basic Dataview.
Language: English
4 kinds presentations of DataView
- List
- Calendar
- Task
- Table
How to use?
LIST
By using LIST keyword, we can generate a list of existing .md files.
Filter: folders
Now we want to limit the items in the list.
LIST
FROM "10-19 Computer Science/12 Computer Network"
Now this list only shows .md files in directory “10-19 Computer Science/12 Computer Network”. For sub-folder, use “/” to split the address.
Filter: tags
LIST
FROM #project
For tags, we don’t need the ”” symbol. We just add #tags into FROM part.
A useful skill is to add status of project into nest part. Like #project/active, use “active” to mark the status of this project. And when we search #project, the result will include #project/active. In this sample of list, TF.DATA API is tagged by #project/archive.
Filter: Mix
For example, we can use keyword “AND” or “OR” to combine different tags or folders.
If we want some categories have high priority, we can use parenthesis like high school math.
Limitation of DataView
We can’t present the contents of our notes. We can only show the name into data view. We can’t search contents too.
So what can Dataview search? The answer is metadata. The metadata of Obsidian:
| Field Name | Description |
|---|---|
file.name | The file name as seen in Obsidians sidebar. |
file.folder | The path of the folder this file belongs to. |
file.path | The full file path, including the files name. |
file.ext | The extension of the file type; generally md. |
file.link | A link to the file. |
file.size | The size (in bytes) of the file. |
file.ctime with Time | The date that the file was created. |
file.cday | The date that the file was created. |
file.mtime with Time | The date that the file was last modified. |
file.mday | The date that the file was last modified. |
file.tags | A list of all unique tags in the note. Subtags are broken down by each level, so #Tag/1/A will be stored in the list as [#Tag, #Tag/1, #Tag/1/A]. |
file.etags | A list of all explicit tags in the note; unlike file.tags, does not break subtags down, i.e. [#Tag/1/A] |
file.inlinks | A list of all incoming links to this file, meaning all files that contain a link to this file. |
file.outlinks | A list of all outgoing links from this file, meaning all links the file contains. |
file.aliases | A list of all aliases for the note as defined via the YAML frontmatter. |
file.tasks | A list of all tasks (I.e., \|[ ] some task) in this file. |
file.lists | A list of all list elements in the file (including tasks); these elements are effectively tasks and can be rendered in task views. |
file.frontmatter | Contains the raw values of all frontmatter in form of key \|value text values; mainly useful for checking raw frontmatter values or for dynamically listing frontmatter keys. |
file.day | Only available if the file has a date inside its file name (of form yyyy-mm-dd or yyyymmdd), or has a Date field/inline field. |
file.starred | if this file has been starred via the Obsidian Core Plugin “Starred Files”. |
How to use metadata in Dataview?
Use WHERE file.xxx <>= xxx to define the filter.
LIST
WHERE file.ctime >= date(2024-01-01)
In this sample, we use WHERE file.ctime >= date(2024-01-01) to find which files are created after 2024-01-01. We can use AND to define a range of date.
LIST
WHERE file.ctime >= date(2025-04-31) AND file.ctime <= date(2025-06-15)
More of this, we can use mtime which means modify time. Use minus ”-“ symbol to exclude some results. Here are the results for files which be modified last week. Use dur(x week/day) to present a duration time.
LIST
WHERE file.mtime >= date(today) - dur(1 day)
How to use metadata to find files?
Properties can be searched by Dataview. If we don’t want to use properties and we just want to add a temp mark into notes. We can use this format to add a mark: keywords::value
The syntax of this filter is: WHERE keywords/property = "value" Here is an example using WHERE status = "archive"
LIST
WHERE status="archive"
Sort and Limit length of your results and MORE
Sort
LIST
WHERE file.mtime <= date(yesterday) - dur(1 day)
SORT file.name ASC
We can sort results based on any fields like file.name or file.mtime. 2 sort methods can be used: ASC or DSEC.
Limit Length
It looks too many items in this list. We can use LIMIT #Length to limit the number of items.
LIST
WHERE file.mtime <= date(today) - dur(1 day)
SORT ASC
LIMIT 5
Table
And we can use table view to present the created time:
TABLE file.ctime AS "Created time"
WHERE file.mtime <= date(today) - dur(1 day)
SORT file.ctime ASC
LIMIT 6
Show all links
We can show a list including all links to this file. **Tips: Only shows links current don’t link for now.
list from [[]] and !outgoing([[]])
Split
regexreplace(file.folder, "^.*\/", "") AS "Area" regexreplace(original string, regular expressions, replace to ?)