### Install Dataview Plugin Source: https://blacksmithgu.github.io/obsidian-dataview/resources/develop-against-dataview Install the Dataview plugin as a development dependency using npm. ```bash npm install -D obsidian-dataview ``` -------------------------------- ### Custom View Script Example Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Example of a custom view script (`view1.js`) that logs messages and calls a function with input arguments. ```javascript console.log(`Loading view1`); function foo(...args) { console.log('foo is called with args', ...args); } foo(input) ``` -------------------------------- ### Function Syntax Example Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Illustrates the basic syntax for calling a Dataview function with parameters. ```dataview functionname(parameter1, parameter2) ``` -------------------------------- ### YAML Frontmatter Example Source: https://blacksmithgu.github.io/obsidian-dataview This example shows how to add metadata to a Markdown file using YAML Frontmatter. Fields like 'author', 'published', and 'tags' are defined at the top of the file. ```markdown --- author: "Edgar Allan Poe" published: 1845 tags: poems --- # The Raven Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore— ``` -------------------------------- ### Install Specific Dataview Version Source: https://blacksmithgu.github.io/obsidian-dataview/resources/develop-against-dataview Install a specific version of the Dataview plugin if the latest version is not desired or available. ```bash npm install obsidian-dataview@0.5.64 ``` -------------------------------- ### Task Examples with Different Metadata Annotations Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/metadata-tasks Illustrates how tasks can be annotated with metadata using both emoji shorthands and inline fields for the same purpose. ```markdown - [x] Completed last Saturday ✅2021-08-22 - [x] Some Done Task [completion:: 2021-08-22] ``` -------------------------------- ### Inline Fields Example Source: https://blacksmithgu.github.io/obsidian-dataview This example demonstrates how to add metadata directly within the content of a Markdown file using inline fields with the `[key:: value]` syntax. This method is functionally equivalent to YAML Frontmatter for Dataview indexing. ```markdown #poems # The Raven From [author:: Edgar Allan Poe], written in (published:: 1845) Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore— ``` -------------------------------- ### Function Vectorization Example Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Demonstrates how functions can be applied to both single values and lists of values, returning a corresponding single value or list. ```dataview lower("YES") = "yes" lower(["YES", "NO"]) = ["yes", "no"] replace("yes", "e", "a") = "yas" replace(["yes", "ree"], "e", "a") = ["yas", "raa"] ``` -------------------------------- ### FROM Statement Examples Source: https://blacksmithgu.github.io/obsidian-dataview/queries/data-commands Select data from different sources like tags, folders, single files, or links. Supports composition with 'and'/'or' and negation with '-'. ```dataview FROM #tag ``` ```dataview FROM "folder" ``` ```dataview FROM "path/to/file" ``` ```dataview FROM [[note]] ``` ```dataview FROM outgoing([[note]]) ``` ```dataview #tag and "folder" ``` ```dataview [[Food]] or [[Exercise]] ``` ```dataview -#tag ``` ```dataview #tag and -"folder" ``` -------------------------------- ### Dataview Modulo Operator Example Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Illustrates the use of the modulo operator (`%`) for calculating the remainder of integer division in Dataview. ```dataview 14 % 2 = 0 14 % 3 = 2 ``` -------------------------------- ### Duration Literals (Minutes) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in minutes, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 m) ``` ```dataview LIST WHERE duration > dur(3 mins) ``` ```dataview LIST WHERE duration > dur(1 minute) ``` ```dataview LIST WHERE duration > dur(3 minutes) ``` -------------------------------- ### List Oldest Incomplete Tasks by File Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure This example demonstrates a complex query for tasks, using WHERE to filter for incomplete tasks, SORT to order them by creation date, LIMIT to restrict the count, and GROUP BY to organize by file. A secondary SORT orders the groups by file creation time. ```dataview TASK WHERE !completed SORT created ASC LIMIT 10 GROUP BY file.link SORT rows.file.ctime ASC ``` -------------------------------- ### Dataview TASK Query Example Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Demonstrates filtering, sorting, and grouping tasks using Dataview's TASK view. Use WHERE clauses for filtering and GROUP BY for organization. ```dataviewjs TASK WHERE contains(text, "#tag") WHERE !completed GROUP BY file.folder ``` -------------------------------- ### Dataview typeof() Function Examples Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Demonstrates the usage of the `typeof()` function to determine the data type of various values in Dataview. ```dataview typeof("text") = "string" typof(1) = "number" typof([1, 2, 3]) = "array" ``` -------------------------------- ### Duration Literals (Months) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in months, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 mo) ``` ```dataview LIST WHERE duration > dur(3 months) ``` -------------------------------- ### Check if String Starts With Prefix Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions The `startswith` function returns `true` if a string begins with the specified prefix, and `false` otherwise. ```javascript startswith("yes", "ye") = true startswith("path/to/something", "path/") = true startswith("yes", "no") = false ``` -------------------------------- ### Dataview Duration Formats Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Examples of different ways to specify duration fields, including various units and abbreviations. ```dataview Example:: 7 hours Example:: 16days Example:: 4min Example:: 6hr7min Example:: 9 years, 8 months, 4 days, 16 hours, 2 minutes Example:: 9 yrs 8 min ``` -------------------------------- ### Calling a Custom View from a Document Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Example of how to call a custom view script (`scripts/view1.js`) from an Obsidian document (`projects/customViews.md`) using `await dv.view()`. ```javascript await dv.view("scripts/view1", { arg1: 'a', arg2: 'b' }) ``` -------------------------------- ### Duration Literals (Seconds) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in seconds, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 s) ``` ```dataview LIST WHERE duration > dur(3 secs) ``` ```dataview LIST WHERE duration > dur(1 second) ``` ```dataview LIST WHERE duration > dur(3 seconds) ``` -------------------------------- ### Duration Literals (Days) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in days, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 d) ``` ```dataview LIST WHERE duration > dur(3 days) ``` -------------------------------- ### Duration Literals (Hours) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in hours, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 h) ``` ```dataview LIST WHERE duration > dur(3 hrs) ``` ```dataview LIST WHERE duration > dur(1 hour) ``` ```dataview LIST WHERE duration > dur(3 hours) ``` -------------------------------- ### TABLE Query with Fields Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Use a TABLE query to display specific fields like 'started', 'file.folder', and 'file.etags'. This query filters pages tagged with #games. ```dataview TABLE started, file.folder, file.etags FROM #games ``` -------------------------------- ### Basic Task Query Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure A simple query to list all tasks within the vault. This serves as a starting point for more complex task management queries. ```dataview TASK ``` -------------------------------- ### Get Page Object by Path Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Fetch a specific page object using its path or link with `dv.page()`. Link resolution and extension detection are automatic. ```javascript dv.page("Index") ``` ```javascript dv.page("books/The Raisin.md") ``` -------------------------------- ### Get Page Paths by Tag Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Retrieve only the file paths of pages matching a specific tag using `dv.pagePaths()`. ```javascript dv.pagePaths("#books") ``` -------------------------------- ### Dataview Inline Text Field Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Example of a simple inline text field. For multiline text, use YAML Frontmatter with the pipe operator. ```dataview Example:: This is some normal text. ``` -------------------------------- ### Specific Date Literals Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of using specific date literals for comparisons, including fixed dates and relative dates like today, tomorrow, and start/end of periods. ```dataview LIST WHERE date.year = date(2021-11-11) ``` ```dataview LIST WHERE date.time = date(2021-09-20T20:17) ``` ```dataview LIST WHERE date.day = date(today) ``` ```dataview LIST WHERE date.now = date(now) ``` ```dataview LIST WHERE date.day = date(tomorrow) ``` ```dataview LIST WHERE date.day = date(yesterday) ``` ```dataview LIST WHERE date.day = date(sow) ``` ```dataview LIST WHERE date.day = date(eow) ``` ```dataview LIST WHERE date.day = date(som) ``` ```dataview LIST WHERE date.day = date(eom) ``` ```dataview LIST WHERE date.day = date(soy) ``` ```dataview LIST WHERE date.day = date(eoy) ``` -------------------------------- ### LIST Query with Computed Additional Information Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Outputs a bullet point list including a computed value as additional information, which can combine multiple fields or logic. This example shows file path and creation day. ```dataview LIST "File Path: " + file.folder + " _(created: " + file.cday + ")_" FROM "Games" ``` -------------------------------- ### LIST WITHOUT ID with Computed Value and Grouping Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Outputs a grouped list with computed values for each group, excluding the file name or group key. This example calculates the number of pages per type. ```dataview LIST WITHOUT ID length(rows) + " pages of type " + key GROUP BY type ``` -------------------------------- ### New Date Expressions: Start and End of Week Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Introduces new date expressions: `date(sow)` for the start of the week and `date(eow)` for the end of the week. ```dataview date(sow) ``` ```dataview date(eow) ``` -------------------------------- ### Execute Dataview Query and Get Rendered Markdown Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Asynchronously execute a Dataview query using `dv.queryMarkdown` to obtain rendered Markdown output. Returns a result object containing the rendered Markdown or indicating success/failure. ```javascript await dv.queryMarkdown("LIST FROM #tag") => { successful: true, value: { "- [[Page 1]]\n- [[Page 2]]" } } ``` -------------------------------- ### Inline DQL with Functions and Conditionals Source: https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline Utilize DQL functions and conditional logic within inline queries for more complex dynamic content. This example shows date differences, task counts, and conditional messages. ```dql `= this.due - date(today)` ``` ```dql `= [[Computer Science Theory]].due - date(today)` ``` ```dql `= choice(this.steps > 10000, "YES!", "**No**, get moving!")` ``` ```dql `= length(filter(link(dateformat(date(today), "yyyy-MM-dd")).file.tasks, (t) => !t.completed))` ``` ```dql `= choice(date(today).weekday > 5, "Take it easy!", "Time to get work done!")` ``` -------------------------------- ### substring(string, start, [end]) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Extracts a portion of a string from a start index to an optional end index. If the end index is omitted, the substring extends to the end of the original string. ```APIDOC ## substring(string, start, [end]) Extracts a portion of a string from a start index to an optional end index. If the end index is omitted, the substring extends to the end of the original string. ### Parameters - **string** (string) - The string to extract from. - **start** (number) - The starting index (inclusive). - **end** (number, optional) - The ending index (exclusive). ### Examples ``` substring("hello", 0, 2) = "he" substring("hello", 2, 4) = "ll" substring("hello", 2) = "llo" substring("hello", 0) = "hello" ``` ``` -------------------------------- ### List Pages by Tag, Folder, and Link Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure This query demonstrates complex source selection using LIST. It fetches pages tagged with '#assignment' within the '30 School' folder, OR pages in '30 School/32 Homeworks' linked from 'School Dashboard Current To Dos'. ```dql ```dataview LIST FROM (#assignment AND "30 School") OR ("30 School/32 Homeworks" AND outgoing([[School Dashboard Current To Dos]])) ``` ``` -------------------------------- ### Execute Custom JavaScript View (Basic) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Load and execute a custom JavaScript view from a specified path using `await dv.view()`. This is an asynchronous operation. ```javascript await dv.view("views/custom", { arg1: ..., arg2: ... }); ``` -------------------------------- ### Get Length of Array or Object Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Returns the number of elements in an array or the number of fields in an object. ```javascript length([]) = 0 length([1, 2, 3]) = 3 length(object("hello", 1, "goodbye", 2)) = 2 ``` -------------------------------- ### Duration Literals (Years) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in years, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 yr) ``` ```dataview LIST WHERE duration > dur(3 years) ``` -------------------------------- ### Basic LIST Query Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Outputs a bullet point list of all files in your vault. This is the simplest form of a LIST query. ```dataview LIST ``` -------------------------------- ### List All Tasks Source: https://blacksmithgu.github.io/obsidian-dataview/resources/examples List all tasks within the 'dataview' folder, including sub-tasks and completed tasks. ```dataview TASK FROM "dataview" ``` -------------------------------- ### Duration Literals (Weeks) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Examples of defining duration literals in weeks, using various abbreviations and full words. ```dataview LIST WHERE duration > dur(1 w) ``` ```dataview LIST WHERE duration > dur(3 wks) ``` ```dataview LIST WHERE duration > dur(1 week) ``` ```dataview LIST WHERE duration > dur(3 weeks) ``` -------------------------------- ### Duration Literals (Combinations) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Demonstrates creating duration literals by combining different time units, using spaces or no spaces between units. ```dataview LIST WHERE duration > dur(1 s, 2 m, 3 h) ``` ```dataview LIST WHERE duration > dur(1 s 2 m 3 h) ``` ```dataview LIST WHERE duration > dur(1s 2m 3h) ``` ```dataview LIST WHERE duration > dur(1second 2min 3h) ``` -------------------------------- ### Table of Pages with Fields and Aggregations Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure Construct a TABLE view showing pages, their 'due' field, tags, and the average of 'working-hours'. This demonstrates selecting specific fields and using aggregation functions. ```dql ```dataview TABLE due, file.tags AS "tags", average(working-hours) ``` ``` -------------------------------- ### Table Query with Date and Type Sorting Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure Creates a table displaying file creation time, appointment type, appointment time, and follow-ups. It filters for notes with the 'follow-ups' field and sorts the results by appointment time. ```dataview TABLE file.ctime, appointment.type, appointment.time, follow-ups FROM "30 Protocols/32 Management" WHERE follow-ups SORT appointment.time ``` -------------------------------- ### dv.markdownTaskList(tasks) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Equivalent to `dv.taskList()`, but returns plain Markdown string. ```APIDOC ## `dv.markdownTaskList(tasks)` ### Description Equivalent to `dv.taskList()`, which renders a task list, but returns plain Markdown. ### Usage ```javascript const markdown = dv.markdownTaskList(dv.pages("#project").file.tasks); dv.paragraph(markdown); ``` ``` -------------------------------- ### Dataview ISO8601 Date Formats Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Examples of various ISO8601 compliant date formats that Dataview automatically recognizes. ```dataview Example:: 2021-04 Example:: 2021-04-18 Example:: 2021-04-18T04:19:35.000 Example:: 2021-04-18T04:19:35.000+06:30 ``` -------------------------------- ### link(path, [display]) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Constructs a link object to a file. An optional display name can be provided. ```APIDOC ## link(path, [display]) ### Description Construct a link object from the given file path or name. If provided with two arguments, the second argument is the display name for the link. ### Parameters - **path** (string) - The path or name of the file to link to. - **display** (string, Optional) - The text to display for the link. ### Examples ```apidoc link("Hello") // => link to page named 'Hello' link("Hello", "Goodbye") // => link to page named 'Hello', displays as 'Goodbye' ``` ``` -------------------------------- ### Dataview Number in YAML Frontmatter Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Example of defining a number field within YAML Frontmatter without quotes. ```yaml --- rating: 8 description: "A nice little horror movie" --- ``` -------------------------------- ### Convert Links to Embedded Equivalents Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Shows how to use the `embed()` function to convert links to their embedded equivalents. The optional second argument can be used to control this conversion. ```dataviewql embed(link) ``` ```dataviewql embed(link, false) ``` -------------------------------- ### Render Headers Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Create HTML headers of different levels (1-6) using `dv.header()`. ```javascript dv.header(1, "Big!"); ``` ```javascript dv.header(6, "Tiny"); ``` -------------------------------- ### Dataview Task Query with Tags Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Example of how to filter tasks based on their associated tags using the `contains()` function in Dataview. ```dataview TASK WHERE contains(tags, "#tag") ``` -------------------------------- ### Dataview Query for Frontmatter Source: https://blacksmithgu.github.io/obsidian-dataview/data-annotation Example of a Dataview query that filters notes based on a nested field defined in the YAML Frontmatter. ```dataview ```dataview LIST WHERE thoughts.rating = 8 ``` ``` -------------------------------- ### dv.io.load(path, [origin-file]) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Asynchronously loads the content of a file from the given path. Relative paths are resolved relative to the optional origin file. Returns the file content as a string or undefined if the file is not found. ```APIDOC ## ⌛ `dv.io.load(path, [origin-file])` ### Description Load the contents of the given path (a link or string) asynchronously. Relative paths will be resolved relative to the optional origin file (defaulting to the current file if not provided). Returns the string contents of the file, or `undefined` if the file does not exist. ### Usage Example ```javascript await dv.io.load("File") // Output: "# File\nThis is an example file..." ``` ``` -------------------------------- ### dv.markdownList(values) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Equivalent to `dv.list()`, but returns plain Markdown string. ```APIDOC ## `dv.markdownList(values)` ### Description Equivalent to `dv.list()`, which renders a list of the given elements, but returns plain Markdown. ### Usage ```javascript const markdown = dv.markdownList([1, 2, 3]); dv.paragraph(markdown); ``` ``` -------------------------------- ### dv.tryQueryMarkdown(source, [file], [settings]) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Executes a Dataview query asynchronously and returns the results as rendered Markdown. Throws a JavaScript exception if the query execution fails. ```APIDOC ## ⌛ `dv.tryQueryMarkdown(source, [file], [settings])` ### Description Exactly the same as `dv.queryMarkdown()`, but throws an error on parse failure. ### Parameters * `source` (string): The Dataview query string. * `file` (string, optional): The file path to resolve the query from (e.g., for `this`). Defaults to the current file. * `settings` (object, optional): Execution settings for running the query. Advanced use case. ### Usage Example ```javascript try { await dv.tryQueryMarkdown("LIST FROM #tag"); } catch (e) { console.error("Markdown query failed:", e); } ``` ``` -------------------------------- ### Basic Dataview Query (LIST) Source: https://blacksmithgu.github.io/obsidian-dataview A fundamental Dataview Query Language (DQL) query that lists all files in your vault. This is the simplest form of a DQL query. ```dql ```dataview LIST ``` ``` -------------------------------- ### Dataview Multiline Text via YAML Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Shows how to define multiline text values using YAML Frontmatter and the pipe operator. ```yaml --- poem: | Because I could not stop for Death, He kindly stopped for me; The carriage held but just ourselves And Immortality. author: "[[Emily Dickinson]]" title: "Because I could not stop for Death" --- ``` -------------------------------- ### Get Link Type Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Determine the type of link using `meta(link).type`. Possible values are 'file', 'header', or 'block'. ```dataview meta([[My Project]]).type = "file" ``` ```dataview meta([[My Project#Next Actions]]).type = "header" ``` ```dataview meta([[My Project#^9bcbe8]]).type = "block" ``` -------------------------------- ### Get Type of Value Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Returns the data type of any given value as a string. Useful for conditional logic based on data type. ```dataview typeof(8) => "number" ``` ```dataview typeof("text") => "string" ``` ```dataview typeof([1, 2, 3]) => "array" ``` ```dataview typeof({ a: 1, b: 2 }) => "object" ``` ```dataview typeof(date(2020-01-01)) => "date" ``` ```dataview typeof(dur(8 minutes)) => "duration" ``` -------------------------------- ### Calendar View by Creation Date Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure Create a CALENDAR view where each page is marked with a dot on its creation date (file.cday). This helps visualize content distribution over time. ```dql ```dataview CALENDAR file.cday ``` ``` -------------------------------- ### elink(url, [display]) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Constructs a link to an external URL. An optional display name can be provided. ```APIDOC ## elink(url, [display]) ### Description Construct a link to an external url (like `www.google.com`). If provided with two arguments, the second argument is the display name for the link. ### Parameters - **url** (string) - The external URL. - **display** (string, Optional) - The text to display for the link. ### Examples ```apidoc elink("www.google.com") // => link element to google.com elink("www.google.com", "Google") // => link element to google.com, displays as "Google" ``` ``` -------------------------------- ### Create Empty List Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Creates an empty list. The `array` alias can also be used. ```dataview list() ``` -------------------------------- ### String Functions: startswith, endswith, padleft, padright, string Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Adds new string manipulation functions: `startswith`, `endswith` for checking string prefixes/suffixes, `padleft` and `padright` for padding strings, and `string` for type conversion. ```dataview startswith(string, prefix) ``` ```dataview endswith(string, suffix) ``` ```dataview padleft(string, length, char) ``` ```dataview padright(string, length, char) ``` ```dataview string(value) ``` -------------------------------- ### Calculating Overtime in Dataview Source: https://blacksmithgu.github.io/obsidian-dataview/reference/expressions Calculates the overtime duration by subtracting 8 hours from the difference between 'end' and 'start' timestamps. Results are aliased as 'Overtime'. ```dataview TABLE start, end, (end - start) - dur(8 h) AS "Overtime" FROM #work ``` -------------------------------- ### LIST Query with Additional Information Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Outputs a bullet point list including an additional piece of information for each file, such as its folder. Only one additional information field can be specified. ```dataview LIST file.folder ``` -------------------------------- ### Inline DQL for Date Calculations Source: https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline Use inline DQL to perform calculations and display dynamic text. This example calculates the time remaining until an exam. ```dql `= date(today)` ``` ```dql `= [[exams]].deadline - date(today)` ``` -------------------------------- ### dv.markdownTable(headers, values) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Equivalent to `dv.table()`, but returns plain Markdown string. ```APIDOC ## `dv.markdownTable(headers, values)` ### Description Equivalent to `dv.table()`, which renders a table with the given list of headers and 2D array of elements, but returns plain Markdown. ### Usage ```javascript // Render a simple table of book info sorted by rating. const table = dv.markdownTable(["File", "Genre", "Time Read", "Rating"], dv.pages("#book") .sort(b => b.rating) .map(b => [b.file.link, b.genre, b["time-read"], b.rating])) dv.paragraph(table); ``` ``` -------------------------------- ### Dataview Query for Frontmatter Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/add-metadata Query notes based on metadata defined in their YAML Frontmatter. This example filters notes where the nested 'thoughts.rating' field is 8. ```dataview LIST WHERE thoughts.rating = 8 ``` -------------------------------- ### Display Files by Modification Time Source: https://blacksmithgu.github.io/obsidian-dataview/resources/examples List all files in the 'books' folder, displaying their last modification time ('mtime') in a table, sorted by modification time in descending order. ```dataview TABLE file.mtime AS "Last Modified" FROM "books" SORT file.mtime DESC ``` -------------------------------- ### Get Link Subpath Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Extract the subpath of a link using `meta(link).subpath`. This will be the heading text or block ID if applicable, otherwise null. ```dataview meta([[My Project#Next Actions]]).subpath = "Next Actions" ``` ```dataview meta([[My Project#^9bcbe8]]).subpath = "9bcbe8" ``` ```dataview meta([[My Project]]).subpath = null ``` -------------------------------- ### Render Dataview Task List Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Use `dv.taskList()` to render Dataview `Task` objects. By default, tasks are grouped by file. Set the second argument to `false` to render a single unified list. ```javascript // List all tasks from pages marked '#project' dv.taskList(dv.pages("#project").file.tasks) ``` ```javascript // List all *uncompleted* tasks from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => !t.completed)) ``` ```javascript // List all tasks tagged with '#tag' from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => t.text.includes("#tag"))) ``` ```javascript // List all tasks from pages marked '#project', without grouping. dv.taskList(dv.pages("#project").file.tasks, false) ``` -------------------------------- ### Execute Custom JavaScript View with CSS Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Load a custom JavaScript view from a folder containing `view.js` and `view.css`. The CSS file will be automatically included. ```javascript await dv.view(".views/view1", { arg1: 'a', arg2: 'b' }); ``` -------------------------------- ### Get Link Path Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Retrieve the file path portion of a link using `meta(link).path`. This works for links to files, headings, and blocks. ```dataview meta([[My Project]]).path = "My Project" ``` ```dataview meta([[My Project#Next Actions]]).path = "My Project" ``` ```dataview meta([[My Project#^9bcbe8]]).path = "My Project" ``` -------------------------------- ### General Literals in Dataview Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Demonstrates various general-purpose literals including numbers, text, links, lists, objects, dates, and durations. ```dataview LIST WHERE file.day.year = 2022 ``` ```dataview LIST WHERE contains(file.name, "Math") ``` ```dataview LIST FROM [[Study MOC]] ``` ```dataview TASK WHERE !completed AND file.day = date(yesterday) ``` ```dataview LIST WHERE end - start > dur(2 days) ``` -------------------------------- ### TABLE WITHOUT ID Query with Fields Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Use TABLE WITHOUT ID to exclude the default file link column. This example displays 'steamid' and 'file.etags'. ```dataview TABLE WITHOUT ID steamid, file.etags AS "File Tags" FROM #games ``` -------------------------------- ### Create List with Values Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Creates a list containing the specified values. The `array` alias can also be used. ```dataview list(1, 2, 3) ``` ```dataview array("a", "b", "c") ``` -------------------------------- ### Extract a Portion of an Array Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions The `slice` function returns a shallow copy of a portion of an array. It can select elements from a start index to an end index, or count from the end. ```javascript slice([1, 2, 3, 4, 5], 3) = [4, 5] => All items from given position, 0 as first slice(["ant", "bison", "camel", "duck", "elephant"], 0, 2) = ["ant", "bison"] => First two items slice([1, 2, 3, 4, 5], -2) = [4, 5] => counts from the end, last two items slice(someArray) => a copy of someArray ``` -------------------------------- ### object(key1, value1, ...) Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Creates a new object with alternating string keys and values. An empty call creates an empty object. ```APIDOC ## object(key1, value1, ...) ### Description Creates a new object with the given keys and values. Keys and values should alternate in the call, and keys should always be strings/text. ### Parameters - **key1** (string) - The first key for the object. - **value1** (any) - The value associated with the first key. - **...** (keyN, valueN) - Additional alternating keys and values. ### Examples ```apidoc object() // => empty object object("a", 6) // => object which maps "a" to 6 object("a", 4, "c", "yes") // => object which maps a to 4, and c to "yes" ``` ``` -------------------------------- ### Extract substring in DataviewJS Source: https://blacksmithgu.github.io/obsidian-dataview/changelog The `substring` function is now available for DataviewJS users to extract portions of strings. It takes the string, a start index, and an optional end index. ```javascript substring(string, start[, end]) ``` -------------------------------- ### Custom Table Header with Markdown Link Source: https://blacksmithgu.github.io/obsidian-dataview/changelog Demonstrates how to use arbitrary markdown, including links, within Dataview table headers. This allows for more dynamic and informative table column titles. ```dataviewql TABLE (1 + 2) AS "[[File]]" ``` -------------------------------- ### General DQL Query Structure Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure A DQL query follows a general pattern starting with a Query Type, followed by an optional FROM statement, and then zero or more other data commands. ```dql ```dataview FROM ... ``` ``` -------------------------------- ### Link Literal as Source Source: https://blacksmithgu.github.io/obsidian-dataview/reference/literals Utilize a link literal to specify a source file or MOC for your query. ```dataview LIST FROM [[Study MOC]] ``` -------------------------------- ### Get Link Display Text Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Access the display text of a link using `meta(link).display`. Returns null if the link does not have a defined display text. ```dataview meta([[2021-11-01|Displayed link text]]).display = "Displayed link text" ``` ```dataview meta([[2021-11-01]]).display = null ``` -------------------------------- ### Querying Object Properties Source: https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata Access nested object properties in Dataview queries using dot notation (e.g., `obj.key1`). This example displays object properties in a table. ```dataview TABLE obj.key1, obj.key2, obj.key3 WHERE file = this.file ``` -------------------------------- ### Render Markdown Task List Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Use `dv.markdownTaskList()` to generate a plain Markdown task list string. This is equivalent to `dv.taskList()` but returns Markdown text. ```javascript const markdown = dv.markdownTaskList(dv.pages("#project").file.tasks); dv.paragraph(markdown); ``` -------------------------------- ### dv.taskList(tasks, groupByFile) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Renders a Dataview list of Task objects. By default, tasks are grouped by their origin file. ```APIDOC ## `dv.taskList(tasks, groupByFile)` ### Description Render a dataview list of `Task` objects, as obtained by `page.file.tasks`. By default, this view will automatically group the tasks by their origin file. If you provide `false` as a second argument explicitly, it will instead render them as a single unified list. ### Usage ```javascript // List all tasks from pages marked '#project' dv.taskList(dv.pages("#project").file.tasks) // List all *uncompleted* tasks from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => !t.completed)) // List all tasks tagged with '#tag' from pages marked #project dv.taskList(dv.pages("#project").file.tasks .where(t => t.text.includes("#tag"))) // List all tasks from pages marked '#project', without grouping. dv.taskList(dv.pages("#project").file.tasks, false) ``` ``` -------------------------------- ### Filter Notes by Date Source: https://blacksmithgu.github.io/obsidian-dataview/queries/structure Use the WHERE command to filter notes based on metadata fields. This example selects pages where the 'due' field exists and is before today's date. ```dataview LIST WHERE due AND due < date(today) ``` -------------------------------- ### Create Link to Page Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Constructs a link object to a Dataview page. An optional display name can be provided. ```dataview link("Hello") => link to page named 'Hello' ``` ```dataview link("Hello", "Goodbye") => link to page named 'Hello', displays as 'Goodbye' ``` -------------------------------- ### Get First Non-Null Value from Array Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Returns the first non-null value encountered in an array. Useful for selecting the first available field value from a list of children. ```javascript firstvalue([null, 1, 2]) => 1 firstvalue(children.myField) => If children.myField equals [null, null, "myValue", null], it would return "myValue" ``` -------------------------------- ### Filter Tasks by Urgency Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Filters tasks where the 'urgent' field is true. This example shows how to query for specific metadata on tasks, including child tasks that might match the criteria. ```dataview TASK WHERE urgent ``` -------------------------------- ### Render Markdown List Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Use `dv.markdownList()` to generate a plain Markdown list string. This is equivalent to `dv.list()` but returns Markdown text. ```javascript const markdown = dv.markdownList([1, 2, 3]); dv.paragraph(markdown); ``` -------------------------------- ### WHERE Clause: Filter Incomplete and Old Projects Source: https://blacksmithgu.github.io/obsidian-dataview/queries/data-commands Find projects that are not marked as 'completed' and were created more than a month ago, based on creation time (ctime). ```dataview LIST FROM #projects WHERE !completed AND file.ctime <= date(today) - dur(1 month) ``` -------------------------------- ### LIST WITHOUT ID with Additional Information Source: https://blacksmithgu.github.io/obsidian-dataview/queries/query-types Outputs a bullet point list of an additional information field without the file name or group key. This example shows the 'type' field. ```dataview LIST WITHOUT ID type ``` -------------------------------- ### Inline Dataview JS to Display File Modification Time Source: https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline Embed a JavaScript expression directly in your text using inline `$=` syntax. This example displays the modification time of the current file. ```javascript `$= dv.current().file.mtime` ``` -------------------------------- ### Query All Pages Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Retrieve all pages in your vault using `dv.pages()` without any source filter. ```javascript dv.pages() ``` -------------------------------- ### Inline DQL to Display Current File Name Source: https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline Embed a DQL query directly within your text to display a single value. This example shows how to display the name of the current file. ```dql `= this.file.name` ``` -------------------------------- ### Extract Substring Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Use `substring` to extract a portion of a string. Specify the start index and optionally an end index. If the end index is omitted, the substring extends to the end of the original string. ```javascript substring("hello", 0, 2) = "he" substring("hello", 2, 4) = "ll" substring("hello", 2) = "llo" substring("hello", 0) = "hello" ``` -------------------------------- ### Indexing Through Links Source: https://blacksmithgu.github.io/obsidian-dataview/reference/expressions Access properties of linked pages directly within expressions. Use `[[Page Name]].property` to get a property from a specific page, or `Object.propertyName` if the link is stored in a field. ```dataview [[Assignment Math]].duedate ``` ```dataview Class.timetable ``` -------------------------------- ### dv.tryQuery(source, [file, settings]) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Executes a Dataview query asynchronously and returns the results. Throws a JavaScript exception if the query execution fails. ```APIDOC ## ⌛ `dv.tryQuery(source, [file, settings])` ### Description Exactly the same as `dv.query`, but more convenient in short scripts as execution failures will be raised as JavaScript exceptions instead of a result type. ### Parameters * `source` (string): The Dataview query string. * `file` (string, optional): The file path to resolve the query from (e.g., for `this`). Defaults to the current file. * `settings` (object, optional): Execution settings for running the query. Advanced use case. ### Usage Example ```javascript try { await dv.tryQuery("LIST FROM #tag"); } catch (e) { console.error("Query failed:", e); } ``` ``` -------------------------------- ### Dataview JavaScript (JS) for Grouped Lists Source: https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline Use `dataviewjs` codeblocks for advanced data manipulation and custom views with JavaScript. This example filters pages by tag and rating, then groups and lists them by genre. ```javascript ```dataviewjs let pages = dv.pages("#books and -#books/finished").where(b => b.rating >= 7); for (let group of pages.groupBy(b => b.genre)) { dv.header(3, group.key); dv.list(group.rows.file.name); } ``` ``` -------------------------------- ### List Files by Date in Title Source: https://blacksmithgu.github.io/obsidian-dataview/resources/examples List files that have a date in their title (format: YYYY-MM-DD), sorted by date in descending order. It filters for files where 'file.day' is present. ```dataview LIST file.day WHERE file.day SORT file.day DESC ``` -------------------------------- ### Styling Dataview Tables with CSS Snippets Source: https://blacksmithgu.github.io/obsidian-dataview/resources/faq Apply custom CSS to Dataview tables by defining CSS classes in your Obsidian settings and referencing them in your CSS snippets. This example targets tables with the class 'myTable'. ```css .myTable dataview.table { background-color: green } ``` -------------------------------- ### dv.view(path, input) Source: https://blacksmithgu.github.io/obsidian-dataview/api/code-reference Loads and executes a custom DataviewJS view script from a specified path, passing it input data. This is an asynchronous function. ```APIDOC ## `dv.view(path, input)` ### Description Complex function which allows for custom views. Will attempt to load a JavaScript file at the given path, passing it `dv` and `input` and allowing it to execute. This allows for you to re-use custom view code across multiple pages. Note that this is an asynchronous function since it involves file I/O - make sure to `await` the result! ### Method `await dv.view(path, input)` ### Parameters #### Parameters - **path** (string) - Required - The path to the custom view script (relative to the vault root). - **input** (any) - Optional - Data to be passed to the view script. ### Examples ```dataviewjs // Example with data argument await dv.view("views/custom", { arg1: ..., arg2: ... }); // Example with custom CSS file in the same folder // views/custom // -> view.js // -> view.css await dv.view("views/custom", { arg1: 'a', arg2: 'b' }); ``` ### Notes - View scripts have access to the `dv` object (the API object), and an `input` object which is exactly whatever the second argument of `dv.view()` was. - `dv.view()` cannot read from directories starting with a dot, like `.views`. - Directory paths always originate from the vault root. ``` -------------------------------- ### Create Empty Object Source: https://blacksmithgu.github.io/obsidian-dataview/reference/functions Creates an empty object. Useful for initializing data structures. ```dataview object() ```