Files
gh-nathanvale-side-quest-ma…/skills/second-brain/reference/dataview-patterns.md
2025-11-30 08:42:13 +08:00

8.1 KiB

Dataview Patterns for PARA

Advanced Dataview queries for PARA-based task and project management

Table of Contents


Core Concepts

Query Types

Type Purpose Level
LIST Bullet list of pages Page
TABLE Tabular data Page
TASK Interactive task list Task
CALENDAR Date-based calendar view Page

Key Difference: Page vs Task Level

Page-level queries (LIST, TABLE, CALENDAR):

TABLE status, priority
FROM "07_Tasks"
WHERE status != "done"

Returns files matching criteria.

Task-level queries (TASK):

TASK
FROM "07_Tasks"
WHERE !completed

Returns individual tasks from files, can be checked off interactively.


Self-Referential Queries

Problem: Hardcoded names break when files are renamed.

-- BAD: Breaks if "My Project" is renamed
WHERE contains(project, "[[My Project]]")

Solution: Use this.file.link for robust self-references.

-- GOOD: Works even after rename
WHERE contains(project, this.file.link)

In Project Notes

Show all tasks linked to this project:

TASK
FROM "07_Tasks"
WHERE contains(project, this.file.link) AND !completed
SORT priority DESC

In Area Notes

Show all tasks linked to this area:

TASK
FROM "07_Tasks"
WHERE contains(area, this.file.link) AND !completed
GROUP BY file.link

Show all projects in this area:

TABLE status, target_completion as "Due"
FROM "01_Projects"
WHERE contains(area, this.file.link) AND status = "active"
SORT target_completion ASC

Task Queries

All Open Tasks

TASK
FROM "07_Tasks"
WHERE !completed
SORT priority DESC

Tasks Due This Week

TASK
FROM "07_Tasks"
WHERE due_date <= date(today) + dur(7 days)
  AND due_date >= date(today)
  AND !completed
SORT due_date ASC

Overdue Tasks

TASK
FROM "07_Tasks"
WHERE due_date < date(today) AND !completed
SORT due_date ASC

Tasks by Priority

TASK
FROM "07_Tasks"
WHERE !completed AND priority = "urgent"
GROUP BY file.link

Tasks Grouped by Project

TASK
FROM "07_Tasks"
WHERE !completed
GROUP BY project
SORT rows.priority DESC

High Priority Tasks (Priority >= 42)

Using numeric priority for fine-grained control:

TASK
FROM "07_Tasks"
WHERE !completed AND priority >= 42
SORT priority DESC
LIMIT 10

Project Queries

Active Projects Dashboard

TABLE
  status,
  target_completion as "Due",
  area as "Area",
  length(filter(file.tasks, (t) => !t.completed)) AS "Open Tasks"
FROM "01_Projects"
WHERE status = "active"
SORT target_completion ASC

Projects Needing Review

Show projects not reviewed in the last 7 days:

TABLE
  status,
  reviewed as "Last Review",
  target_completion as "Due"
FROM "01_Projects"
WHERE status = "active"
  AND (reviewed < date(today) - dur(7 days) OR !reviewed)
SORT reviewed ASC

Projects by Area

LIST
FROM "01_Projects"
WHERE status = "active"
GROUP BY area

Stalled Projects

Projects with no tasks or all tasks completed:

TABLE status, target_completion
FROM "01_Projects"
WHERE status = "active"
  AND length(filter(file.tasks, (t) => !t.completed)) = 0

Resource Queries

Resources use an areas: array field to link to one or more areas. This enables powerful cross-area queries.

Resources in This Area

Place in an Area note to show all linked resources:

TABLE source, author, reviewed as "Last Review"
FROM "03_Resources"
WHERE contains(areas, this.file.link)
SORT reviewed DESC

All Resources by Area

TABLE areas, source, author
FROM "03_Resources"
SORT file.name ASC

Resources Needing Review

TABLE
  source,
  areas,
  reviewed as "Last Review"
FROM "03_Resources"
WHERE reviewed < date(today) - dur(30 days) OR !reviewed
SORT reviewed ASC

Resources by Source Type

TABLE author, areas
FROM "03_Resources"
WHERE source = "book"
SORT file.name ASC

Recently Added Resources

TABLE source, author, areas
FROM "03_Resources"
SORT created DESC
LIMIT 10

Resources Spanning Multiple Areas

Find resources that relate to multiple areas:

TABLE areas, source
FROM "03_Resources"
WHERE length(areas) > 1

Review Tracking

The Review Pattern

Add these fields to frontmatter:

reviewed: 2025-01-15      # Last review date
review_period: 7d         # How often to review (default: 7d)

Projects Due for Review

TABLE
  reviewed as "Last Review",
  (date(today) - reviewed).days + " days ago" as "Age"
FROM "01_Projects"
WHERE status = "active"
  AND (
    reviewed < (date(today) - dur(default(review_period, "7d")))
    OR !reviewed
  )
SORT reviewed ASC

Tasks Due for Review

TASK
FROM "07_Tasks"
WHERE !completed
  AND (reviewed < date(today) - dur(7 days) OR !reviewed)
GROUP BY file.link

Weekly Review Dashboard

Notes modified in last 14 days that haven't been reviewed:

TABLE file.mtime as "Modified"
FROM ""
WHERE file.mtime > (date(now) - dur(14 days))
  AND !reviewed
  AND file.folder != "templates"
SORT file.mtime DESC

Dashboard Queries

Master Dashboard

Urgent Tasks

TASK
FROM "07_Tasks"
WHERE !completed AND priority = "urgent"
LIMIT 5

Due This Week

TABLE project, due_date, priority
FROM "07_Tasks"
WHERE !completed
  AND due_date <= date(today) + dur(7 days)
SORT due_date ASC
LIMIT 10

Projects Needing Attention

TABLE
  target_completion as "Due",
  (reviewed < date(today) - dur(7 days)) as "Needs Review"
FROM "01_Projects"
WHERE status = "active"
SORT target_completion ASC
LIMIT 5

Inbox Count

LIST WITHOUT ID length(rows) + " items in inbox"
FROM "00_Inbox"
GROUP BY true

Common Patterns

Counting Items

LIST WITHOUT ID length(rows) + " active projects"
FROM "01_Projects"
WHERE status = "active"
GROUP BY true

Date Calculations

TABLE
  target_completion as "Due",
  (target_completion - date(today)).days + " days left" as "Countdown"
FROM "01_Projects"
WHERE status = "active" AND target_completion
SORT target_completion ASC
-- Check if frontmatter link contains a specific note
WHERE contains(project, [[Project Name]])

-- Self-referential (recommended)
WHERE contains(area, this.file.link)

Default Values

-- Use default() for missing fields
WHERE reviewed < (date(today) - dur(default(review_period, "7d")))

Child Tasks

Child tasks (indented under parent) belong to parent:

TASK
WHERE !completed
-- Will include completed children if parent is incomplete

To exclude specific children:

TASK
WHERE !completed AND !contains(text, "optional")

Troubleshooting

Query Returns Nothing

  1. Check folder path: FROM "01_Projects" - case sensitive!
  2. Check field names: status vs Status matters
  3. Check field values: "active" vs active (quotes matter for strings)

Problem: WHERE area = [[My Area]] doesn't work

Solution: Use contains() for link fields:

WHERE contains(area, [[My Area]])
-- or self-referential
WHERE contains(area, this.file.link)

Tasks Not Appearing

  1. Check if using TASK query type (not TABLE)
  2. Check if tasks are in the right folder
  3. Check if !completed filter is correct

Slow Queries

  1. Add folder constraints: FROM "01_Projects" instead of FROM ""
  2. Limit results: LIMIT 20
  3. Enable lazy loading in Dataview settings

Reference compiled from Dataview documentation and community best practices.