%% date:: [[2023-05-09]] parent:: %% # [[Dataview Examples]] Below are some examples of use cases with Dataview and the queries for them, so that you can reuse them. ### Return based on file path The query below returns the file link and created date for pages from the folder `Exandria` that also have `Port Damali` in the file path. This holds true for files in `Exandria/Port Damali` but also for those in `Exandria/Menagerie Coast/Port Damali`, for example. > ```dataview > table file.cday as "Date Created" > from "Exandria" > where contains(file.path, "Port Damali") > sort file.name asc > ``` Here's the sample result returned: ![[dataview-return-based-on-file-path.png]] ### Return files in a folder that aren't in a subfolder Given a folder `ttrpgs` that has many folders in it, including `ttrpgs/Temporary White Circle`, return all files except those in `ttrpgs/Temporary White Circle`: > ```dataview > TABLE file.folder as "Folder" from "ttrpgs" > where !contains(file.folder,"Temporary") > ``` ### Return tasks with a tag > ```dataview > TASK from "foldername" > where contains(text,"mytag") > ``` ### Return tasks, grouped by link Add `group by file.link` to show the file that each task came from. > ```dataview > TASK from "Daily" > where contains(text,"2022-10-08") > group by file.link > ``` This will display something like this: ![[dataview-task-group-by-link.png]] ### Calculate dates Use the metadata somewhere in your note: > startDate:: 2022-07-10 > endDate:: 2022-07-14 Then, use the Dataview query below: > ```dataview > TABLE startDate, endDate, (endDate - startDate) AS Duration FROM "Daily" > WHERE endDate > SORT endDate desc > ``` You'll get the following table: ![[dataview-return-calculate-dates.png]] ### Display a table with authors and titles, but grouped by author For notes with the field `Author`, use this query: > ```dataview > TABLE rows.title as "Title" from "Readwise/Books" > where Author > Group by Author > ``` For example, if you had two books, *A Spell for Chameleon* and *Source of Magic*, both of which had `Author: Piers Anthony` in the frontmatter, you'd get this result: ![[dataview-return-grouped-authors.png]] ### Return files in the last month > ```dataview > TABLE file.mtime as "Last Modified", file.tags as Tags > WHERE file.mtime >= date(today) - dur(1 month) > ``` This returns notes that were modified within the last month, as well as their tags, like this: ![[dataview-return-last-month.png]] *(Thanks to @Lumber_Jones on Discord for asking this question.)* ### Return unprocessed files from a folder in the last month If you use the [[Readwise Official]] plugin, here's a query that returns all new Readwise-imported notes with the tag `#TVZ` (you can change this to whatever tag you use for your inbox) that were *modified* within the last month. > ```dataview > TABLE file.mday from "Readwise" > where file.mtime >= date(today) - dur(1 month) > and file.name != "Readwise Syncs" > and contains(file.tags,"TVZ") > sort file.mtime desc > ``` The query returns something like this: ![[dataview-readwise-last-month.png]] ### Count number of results returned This returns notes of `type: session` whose filenames start with `2022`: > ```dataview > table length(rows) as Number from "TTRPGs" > where contains(type,"session") and contains(file.name,"2022") > group by type > ```