Dataview Query Examples

This note contains examples of useful Dataview queries that you can copy and adapt for your own dashboards.

Basic Queries

Simple Table

TABLE
    field1 as "Column 1",
    field2 as "Column 2"
FROM "path/to/folder"
SORT field1 DESC

List View

LIST
FROM "path/to/folder"
WHERE condition

Task View

TASK
FROM "path/to/folder"
WHERE !completed

Advanced Queries

Grouping Data

TABLE rows.field1 as "Field 1"
FROM "path/to/folder"
GROUP BY field2 as "Group"

Calendar View

CALENDAR file.day
FROM "Daily"

Calculations

TABLE
    length(rows) as "Count",
    sum(rows.number_field) as "Sum",
    average(rows.number_field) as "Average"
FROM "path/to/folder"
GROUP BY category

Date Filtering

TABLE date as "Date"
FROM "path/to/folder"
WHERE date >= date(today) - dur(1 week)

Task Progress

TABLE
    length(filter(file.tasks.completed, (t) => t = true)) + " / " + length(file.tasks) as "Completed",
    round(length(filter(file.tasks.completed, (t) => t = true)) / length(file.tasks) * 100) + "%" as "Progress"
FROM "path/to/folder"
WHERE length(file.tasks) > 0

Query By Metadata

By Tags

TABLE
FROM #tag1 and #tag2

By YAML Property

TABLE
FROM "path/to/folder"
WHERE property = "value"

By File Path

TABLE
FROM "path/to/folder" OR "another/path"

Embedding and Formatting

Inline Field

INLINE
FROM "path/to/folder"

Custom Formatting

TABLE
    "<span style='color: red'>" + field + "</span>" as "Styled Field"
FROM "path/to/folder"
TABLE
    "[[" + file.name + "]]" as "Link"
FROM "path/to/folder"

Common Use Cases

Recent Notes

TABLE file.mtime as "Last Modified"
WHERE file.mtime > date(today) - dur(1 week)
SORT file.mtime DESC

Reading List

TABLE
    author as "Author",
    (status = "completed" ? "✅" : "📖") as "Status"
FROM "03-Resources"
WHERE contains(tags, "book")
SORT status ASC, file.mtime DESC

Project Status Overview

TABLE
    status as "Status",
    started as "Started",
    round(length(filter(file.tasks.completed, (t) => t = true)) / length(file.tasks) * 100) + "%" as "Progress"
FROM "01-Projects"
WHERE length(file.tasks) > 0
SORT status ASC, file.mtime DESC

Daily Notes Summary

TABLE
    dateformat(file.day, "ccc, MMM dd") as "Date",
    file.outlinks as "Links"
FROM "Daily"
SORT file.day DESC
LIMIT 7
LIST
FROM ""
WHERE contains(tags, this.file.tags)
AND file.name != this.file.name

Tips for Effective Queries

  1. Start simple: Begin with basic queries and gradually add complexity
  2. Use aliases: Rename columns with as "New Name" for readability
  3. Test incrementally: Add one condition at a time when building complex queries
  4. Use comments: Add comments above queries to explain what they do
  5. Optimize performance: Limit results and avoid unnecessary calculations for large vaults
  6. Be specific: Use precise paths and conditions to get exactly what you need