Dataview Skill
This skill enables Claude Code to create valid Dataview queries for dynamically listing and aggregating notes in Obsidian.
Overview
Dataview is a community plugin that treats an Obsidian vault as a database. It provides three query methods:
- DQL (Dataview Query Language) - SQL-like queries in code blocks
- Inline queries - Single-value queries embedded in text
- DataviewJS - JavaScript API for complex logic
Data Sources
Dataview indexes metadata from:
- Frontmatter (YAML properties)
- Inline fields in note body
- Implicit fields (file metadata)
- Tags and links
Inline Field Syntax
Key:: Value
[Key:: Value] Inline, hidden in reading view
(Key:: Value) Inline, visible in reading view
Rating:: 8
Author:: [[Jane Smith]]
Status:: #in-progress
Due:: 2024-02-15
Implicit Fields (Always Available)
| Field |
Type |
Description |
file.name |
String |
File name without extension |
file.folder |
String |
Folder path |
file.path |
String |
Full file path |
file.ext |
String |
File extension |
file.link |
Link |
Link to the file |
file.size |
Number |
Size in bytes |
file.ctime |
Date |
Creation time |
file.mtime |
Date |
Modification time |
file.day |
Date |
Date from daily note filename |
file.tags |
Array |
All tags including nested |
file.etags |
Array |
Explicit tags only |
file.inlinks |
Array |
Incoming links |
file.outlinks |
Array |
Outgoing links |
file.aliases |
Array |
Aliases from frontmatter |
file.tasks |
Array |
All tasks in file |
file.lists |
Array |
All list items in file |
file.frontmatter |
Object |
Raw frontmatter object |
file.starred |
Boolean |
Is bookmarked |
Task-Specific Fields
| Field |
Type |
Description |
status |
String |
Task status character |
checked |
Boolean |
Is task checked |
completed |
Date |
Completion date |
fullyCompleted |
Boolean |
Task and subtasks done |
text |
String |
Task text |
visual |
String |
Text for display |
line |
Number |
Line number |
lineCount |
Number |
Lines the task spans |
path |
String |
File path |
section |
Link |
Section containing task |
tags |
Array |
Tags in task |
outlinks |
Array |
Links in task |
link |
Link |
Link to task |
children |
Array |
Subtasks |
task |
Boolean |
Is a task |
subtasks |
Array |
All subtasks |
real |
Boolean |
Is real task vs list item |
header |
Link |
Header above task |
DQL Query Structure
```dataview
<QUERY-TYPE> <fields>
FROM <source>
WHERE <condition>
SORT <field> ASC/DESC
GROUP BY <field>
FLATTEN <field>
LIMIT <number>
### Query Types
| Type | Purpose | Output |
|------|---------|--------|
| `LIST` | Bullet list of links | List |
| `LIST WITHOUT ID` | List without file links | List |
| `TABLE` | Table with columns | Table |
| `TABLE WITHOUT ID` | Table without file column | Table |
| `TASK` | Interactive task list | Tasks |
| `CALENDAR` | Calendar by date field | Calendar |
## FROM Clause (Data Sources)
```sql
FROM "" -- All files in vault
FROM "Folder" -- Specific folder
FROM "Folder/Subfolder" -- Nested folder
FROM #tag -- Files with tag
FROM #tag/nested -- Nested tags
FROM [[Note]] -- Files linking TO this note
FROM outgoing([[Note]]) -- Files this note links TO
FROM "Folder" AND #tag -- Combine with AND
FROM "Folder" OR "Other" -- Combine with OR
FROM -"Folder" -- Exclude folder
FROM #tag AND -#archived -- Include and exclude
Source Operators
| Operator |
Description |
AND |
Both conditions must match |
OR |
Either condition matches |
- |
Negate/exclude source |
"path" |
Folder or file path |
#tag |
Tag |
[[link]] |
Incoming links |
outgoing([[link]]) |
Outgoing links |
WHERE Clause (Filtering)
Comparison Operators
| Operator |
Description |
= |
Equals |
!= |
Not equals |
< |
Less than |
> |
Greater than |
<= |
Less or equal |
>= |
Greater or equal |
Logical Operators
| Operator |
Description |
AND |
Both conditions |
OR |
Either condition |
! |
Negation |
Common WHERE Patterns
WHERE status = "active"
WHERE rating >= 4
WHERE file.mtime >= date(today) - dur(7 days)
WHERE contains(tags, "#project")
WHERE !completed
WHERE author = [[Jane Smith]]
WHERE file.name != "Index"
WHERE date >= date(2024-01-01) AND date < date(2024-02-01)
WHERE contains(file.folder, "Projects")
WHERE length(file.tags) > 0
WHERE any(file.tags, (t) => startswith(t, "#book"))
WHERE all(tasks, (t) => t.completed)
Null/Empty Checks
WHERE field
WHERE !field
WHERE field = null
WHERE field != null
SORT Clause
SORT file.name ASC
SORT rating DESC
SORT file.mtime DESC
SORT status ASC, priority DESC
SORT date(due) ASC
GROUP BY Clause
GROUP BY status
GROUP BY file.folder
GROUP BY dateformat(file.ctime, "yyyy-MM")
GROUP BY choice(rating >= 4, "Good", "Other")
When grouped, access items via rows field:
```dataview
TABLE length(rows) AS Count, rows.file.link AS Files
FROM "Projects"
GROUP BY status
## FLATTEN Clause
Expands arrays into separate rows:
```sql
FLATTEN file.tags AS tag
FLATTEN authors AS author
FLATTEN file.lists.text AS item
LIMIT Clause
LIMIT 10
LIMIT 5
Functions Reference
String Functions
| Function |
Description |
contains(str, substr) |
Check substring |
startswith(str, prefix) |
Check prefix |
endswith(str, suffix) |
Check suffix |
length(str) |
String length |
lower(str) |
Lowercase |
upper(str) |
Uppercase |
replace(str, pat, rep) |
Replace pattern |
regexreplace(str, pat, rep) |
Regex replace |
regexmatch(str, pattern) |
Regex match |
split(str, delim) |
Split to array |
join(array, delim) |
Join array |
substring(str, start, end) |
Substring |
truncate(str, len, suffix) |
Truncate with suffix |
padleft(str, len, char) |
Pad left |
padright(str, len, char) |
Pad right |
Numeric Functions
| Function |
Description |
number(string) |
Extract first number from string |
round(num, digits) |
Round number |
trunc(num) |
Remove decimal point |
floor(num) |
Round down |
ceil(num) |
Round up |
min(a, b, ...) |
Minimum value |
max(a, b, ...) |
Maximum value |
sum(array) |
Sum of array |
product(array) |
Product of array |
average(array) |
Average of array |
minby(array, func) |
Min by function |
maxby(array, func) |
Max by function |
Date Functions
| Function |
Description |
date(value) |
Parse to date |
date(today) |
Today's date |
date(now) |
Current datetime |
date(tomorrow) |
Tomorrow |
date(yesterday) |
Yesterday |
date(sow) |
Start of week |
date(eow) |
End of week |
date(som) |
Start of month |
date(eom) |
End of month |
date(soy) |
Start of year |
date(eoy) |
End of year |
dur(duration) |
Parse duration |
dateformat(date, fmt) |
Format date |
durationformat(dur, fmt) |
Format duration |
localtime(date) |
To local time |
striptime(date) |
Remove time component |
Duration Syntax
dur(1 day)
dur(2 weeks)
dur(3 months)
dur(1 year)
dur(2 hours)
dur(30 minutes)
dur(1 day, 2 hours)
Date Format Tokens
| Token |
Description |
Example |
yyyy |
4-digit year |
2024 |
yy |
2-digit year |
24 |
MM |
2-digit month |
01-12 |
M |
Month |
1-12 |
MMMM |
Full month |
January |
MMM |
Short month |
Jan |
dd |
2-digit day |
01-31 |
d |
Day |
1-31 |
EEEE |
Full weekday |
Monday |
EEE |
Short weekday |
Mon |
HH |
24-hour |
00-23 |
hh |
12-hour |
01-12 |
mm |
Minutes |
00-59 |
ss |
Seconds |
00-59 |
a |
AM/PM |
AM |
Array Functions
| Function |
Description |
length(array) |
Array length |
contains(array, val) |
Check membership |
econtains(array, val) |
Exact contains |
containsword(str, word) |
Contains word |
reverse(array) |
Reverse array |
sort(array) |
Sort ascending |
flat(array) |
Flatten nested |
slice(array, start, end) |
Slice array |
filter(array, func) |
Filter by predicate |
map(array, func) |
Transform elements |
all(array, func) |
All match predicate |
any(array, func) |
Any match predicate |
none(array, func) |
None match predicate |
nonnull(array) |
Remove nulls |
unique(array) |
Unique values |
Lambda Syntax
filter(rows, (r) => r.status = "done")
map(file.tags, (t) => upper(t))
any(tasks, (t) => !t.completed)
all(authors, (a) => contains(a, "Smith"))
Object Functions
| Function |
Description |
object(key, val, ...) |
Create object |
list(v1, v2, ...) |
Create list |
default(val, fallback) |
Default if null |
choice(cond, t, f) |
Ternary |
typeof(val) |
Get type |
meta(link) |
Get link metadata |
embed(link, display) |
Embed link |
link(path, display) |
Create link |
elink(url, display) |
External link |
Utility Functions
| Function |
Description |
hash(val) |
Hash value |
localtime(date) |
To local timezone |
striptime(date) |
Remove time |
Inline Queries
Single-value queries embedded in text:
Today is `= date(today)`
Files in vault: `= length(filter(this.file.folder, (x) => x))`
Last modified: `= dateformat(this.file.mtime, "yyyy-MM-dd")`
Total tasks: `= length(filter(this.file.tasks, (t) => !t.completed))`
Progress: `= round(length(filter(this.file.tasks, (t) => t.completed)) / length(this.file.tasks) * 100)` %
Inline Query Syntax
| Syntax |
Description |
`= expression` |
Evaluate expression |
this |
Current file |
this.field |
Field from current file |
DataviewJS
JavaScript queries for complex logic:
```dataviewjs
// List files modified today
const today = dv.date("today");
const files = dv.pages()
.where(p => p.file.mtime >= today)
.sort(p => p.file.mtime, "desc");
dv.list(files.map(p => p.file.link));
```
DataviewJS API
Page Queries
dv.pages()
dv.pages('"Folder"')
dv.pages("#tag")
dv.pages("[[Link]]")
dv.page("path/to/note")
dv.current()
Output Methods
dv.list(items)
dv.taskList(tasks, groupByFile)
dv.table(headers, rows)
dv.paragraph(text)
dv.header(level, text)
dv.span(text)
dv.el(tag, text, attrs)
dv.execute(source)
dv.executeJs(source)
Utility Methods
dv.date(input)
dv.duration(input)
dv.compare(a, b)
dv.equal(a, b)
dv.clone(value)
dv.parse(text)
dv.io.load(path)
dv.io.csv(path)
dv.io.normalize(path)
dv.array(items)
dv.fileLink(path, embed, display)
dv.sectionLink(path, section, embed, display)
dv.blockLink(path, block, embed, display)
DataArray Methods
.where(predicate)
.filter(predicate)
.map(func)
.flatMap(func)
.mutate(func)
.limit(n)
.slice(start, end)
.concat(other)
.indexOf(value)
.find(predicate)
.findIndex(predicate)
.includes(value)
.join(sep)
.sort(key, direction, comparator)
.groupBy(key)
.groupIn(key)
.distinct(key)
.every(predicate)
.some(predicate)
.none(predicate)
.first()
.last()
.to(type)
.into(func)
.forEach(func)
.array()
.expand(func)
DataviewJS Examples
Table with Computed Columns
```dataviewjs
const pages = dv.pages("#project")
.where(p => p.status != "archived")
.sort(p => p.priority, "desc");
dv.table(
["Project", "Status", "Due", "Days Left"],
pages.map(p => [
p.file.link,
p.status,
p.due,
p.due ? Math.floor((dv.date(p.due) - dv.date("today")) / (1000 * 60 * 60 * 24)) : "N/A"
])
);
```
Grouped Task List
```dataviewjs
const tasks = dv.pages("#project")
.file.tasks
.where(t => !t.completed)
.groupBy(t => t.section);
for (let group of tasks) {
dv.header(4, group.key);
dv.taskList(group.rows, false);
}
```
Progress Bars
```dataviewjs
const projects = dv.pages("#project");
for (let p of projects) {
const tasks = p.file.tasks;
const done = tasks.where(t => t.completed).length;
const total = tasks.length;
const pct = total > 0 ? Math.round(done / total * 100) : 0;
dv.paragraph(`**${p.file.link}**: ${done}/${total} (${pct}%)`);
dv.span(`<progress value="${pct}" max="100"></progress>`);
}
```
Complete Examples
Project Dashboard
```dataview
TABLE
status AS "Status",
priority AS "Priority",
due AS "Due Date",
dateformat(file.mtime, "yyyy-MM-dd") AS "Updated"
FROM #project
WHERE status != "archived"
SORT priority DESC, due ASC
```
Reading List
```dataview
TABLE WITHOUT ID
file.link AS "Book",
author AS "Author",
rating AS "Rating",
dateformat(finished, "MMM yyyy") AS "Finished"
FROM #book
WHERE finished
SORT finished DESC
LIMIT 10
```
Tasks Due This Week
```dataview
TASK
FROM "Projects"
WHERE !completed
AND due >= date(today)
AND due <= date(today) + dur(7 days)
SORT due ASC
GROUP BY file.link
```
Daily Notes Index
```dataview
LIST WITHOUT ID
file.link + " - " + default(summary, "No summary")
FROM "Daily Notes"
WHERE file.day >= date(today) - dur(30 days)
SORT file.day DESC
```
Tag Cloud
```dataviewjs
const tags = dv.pages()
.flatMap(p => p.file.tags)
.groupBy(t => t)
.map(g => ({ tag: g.key, count: g.rows.length }))
.sort(t => t.count, "desc")
.limit(20);
dv.paragraph(tags.map(t =>
`${t.tag} (${t.count})`
).join(" | "));
```
Calendar Heatmap Data
```dataview
CALENDAR file.day
FROM "Daily Notes"
WHERE file.day
```
Files Modified Recently
```dataview
TABLE
dateformat(file.mtime, "yyyy-MM-dd HH:mm") AS "Modified",
file.size AS "Size"
FROM ""
WHERE file.mtime >= date(today) - dur(7 days)
SORT file.mtime DESC
LIMIT 20
```
Orphan Notes (No Incoming Links)
```dataview
LIST
FROM ""
WHERE length(file.inlinks) = 0
AND file.name != "Index"
SORT file.name ASC
```
Notes Linking Here
```dataview
LIST
FROM [[]]
SORT file.name ASC
```
Common Patterns
Handling Missing Fields
WHERE default(status, "none") = "active"
WHERE rating != null
WHERE !completed OR completed = null
Date Comparisons
WHERE due = date(today)
WHERE due < date(today)
WHERE due >= date(today) AND due <= date(today) + dur(7 days)
WHERE file.mtime >= date(today) - dur(30 days)
WHERE dateformat(date, "yyyy-MM") = "2024-01"
Working with Arrays
WHERE contains(tags, "#important")
WHERE any(file.tags, (t) => startswith(t, "#project"))
WHERE length(file.outlinks) > 5
WHERE econtains(authors, "Smith")
Aggregations in Groups
GROUP BY status
References