Dataview plugin snippet showcase

Has this feature been added yet? I have successfully generated a LIST of notes, which is useful, but it would be even better if I could transclude. Even more so if I could force only transclusion of their first line, or of a specific heading common to all of them.

2 Likes

I came here looking for exactly the same thing.

@Gnopps I found the answer in this comment on Issue #177!! Worked a treat for me!

Hi all,

I’ve been trying to implement a ‘Dormant projects’ list/query. It should give links to files that contain no unfinished tasks with the #next tag. I’ve tried:

	LIST from #project AND -#next AND "1. Projects" AND !"4. Archive"
	sort file.mtime desc
	limit 5

But this sees a project as dormant if there exists a finished task with the #next tag. I imagine I have to do something with dataviewjs, looping through all unfinished tasks and checking them for #next but I don’t know where to start. Any pointers would be helpful.

This is probably nothing new for you, but I love what Dataview’s task functionality enables in my workflow:

Anytime I write something in a random or daily note which is important and I want to keep for later, like a task, insight, idea etc., I can simply make it a - [ ] task and tag it #insight.

Then I have a note where Dataview gathers all these important snippets from all over the vault with the task query:

TASK
WHERE contains(tags,"insights")
SORT tags asc
4 Likes

I’m trying to create a list of all created/modified notes on a specific day in my daily note for that day but with the following code I get a parsing error. Does anyone know what I did wrong?

LIST
FROM "" -#daily-note
WHERE date(2022-06-17T23:59) - file.mtime <= dur(24 hours) and date(2022-06-17T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc

It says

Expected one of the following: 

'and' or 'or', /FROM/i, EOF, FLATTEN <value> [AS <name>], GROUP BY <value> [AS <name>], LIMIT <value>, SORT field [ASC/DESC], WHERE <expression>

But I’m not that elaborate in Dataview to understand what that means in my case.

Topic

Summary
  • How to filter by duration?

Test

Summary
  • dataview: v0.5.46

Input

Summary

dictionary files

  • Location: “100_Project/02_dataview/Q90_Duration/Q90_test_data”
  • filename : dic_20020301
  • file.mtime: “2002-03-03T19:30:50”
---
Date: 2002-03-01
---
#Project/P03

WorkoutDuration:: 90 minutes



  • filename : dic_20020401
  • file.mtime: “2002-04-03T19:30:50”
---
Date: 2002-04-01
---
#Project/P04

WorkoutDuration:: 120 minutes



  • filename : dic_20020501
  • file.mtime: “2002-05-03T19:30:50”
---
Date: 2002-05-01
---
#Project/P05

WorkoutDuration:: 3 minutes, 7 minutes



DQL10_filter_by_duration_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_filter
_by_duration
_and_TABLE
F_dur_diff:
a duration
no 1.To define a field variable F_dur_diff and
let F_dur_diff = date("2002-05-03T23:59:59") - file.mtime;
2.To filter by F_dur_diff
3.To sort by file.mtime in ascending order
4.To display the result as a table

Notes

Summary

The same codes:

  • To filter the data by duration
Original Example10
```SQL
FLATTEN date("2002-05-03T23:59:59") - file.mtime AS F_dur_diff
WHERE F_dur_diff <= dur("3 months") AND F_dur_diff >= dur("0 months")
```
Another Example11
```SQL
FLATTEN (date("2002-05-03T23:59:59") - file.mtime).months AS F_dur_months
WHERE F_dur_months <= 3 AND F_dur_months >= 0
```
Another Example10B
```SQL

WHERE date("2002-05-03T23:59:59") - file.mtime <= dur("3 months") AND date("2002-05-03T23:59:59") - file.mtime >= dur("0 months")
```
Another Example11B
```SQL

WHERE (date("2002-05-03T23:59:59") - file.mtime).months <= 3 AND (date("2002-05-03T23:59:59") - file.mtime).months >= 0
```
Another Example10C
```SQL

WHERE date("2002-05-03T23:59:59") - file.mtime <= dur("3 months") 
WHERE date("2002-05-03T23:59:59") - file.mtime >= dur("0 months")
```
Another Example11C
```SQL

WHERE (date("2002-05-03T23:59:59") - file.mtime).months <= 3 
WHERE (date("2002-05-03T23:59:59") - file.mtime).months >= 0
```

DQL10_filter_by_duration_and_TABLE

Summary_code
title: DQL10_filter_by_duration_and_TABLE =>1.To define a field variable `F_dur_diff` and `let F_dur_diff = date("2002-05-03T23:59:59") - file.mtime;` 2.To filter by `F_dur_diff` 3.To sort by file.mtime in ascending order 4.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      dateformat(file.mtime,"yyyy-MM-dd HH:mm:ss") AS "mtime",
      F_dur_diff AS "F_dur_diff"
      
FROM "100_Project/02_dataview/Q90_Duration/Q90_test_data" AND !#daily-note

FLATTEN date("2002-05-03T23:59:59") - file.mtime AS F_dur_diff
WHERE F_dur_diff <= dur("3 months") AND F_dur_diff >= dur("0 months")

SORT file.mtime ASC
```

Screenshots(DQL10)


Reference

Summary

I am trying to create a Dataview query that pulls in the first, uncompleted task for each file that is marked as a project.

I tried doing the following, but no dice:

TABLE
  filter(file.tasks, (t, i) => i == 0) AS "Next Action"
FROM -"Templates"
WHERE
  type = "project" AND
  status = "active"
SORT due asc

I am getting an error message that reads:

Expected one of the following:

'(', 'null', boolean, date, duration, file link, list ('[1, 2, 3]'), negated field, number, object ('{ a: 1, b: 2 }'), string, variable

Does anyone have any idea how to achieve this?

My goal is to be able to quickly see, for all of my projects, what is the “Next Action” to take, as determined by the first checkbox on the page that hasn’t been checked.

2 Likes

Hi

I’m trying to add a number of fields together to get a total value for all the fields eg:

Table  sum(rows.est)  sum(rows.S1) + sum(rows.S2) + sum(rows.S3) + sum(rows.S4) + sum(rows.risk) as PpvalueTotal 
where notetype= "#pipeline"
group by "#pipeline"

However if there is more than one instance of the field in a file eg:

S1:: 10
S1:: 20

It does not work - I get:

Dataview: Every row during final data extraction failed with an error; first 3:

        - No implementation found for 'number + array'

Also stupid question but … what is the meaning of ‘rows’ lol? I’ve got this far without being able to find an explanation of what is it is anywhere !

Many thanks - that has worked !
One small favour - I don’t quite understand why and what is going on lol !?
Am I correct that there is some sort of problem with ‘null’ values ?
That mapping function therefore might be ensuring that a zero is returned where otherwise a nothing value might be returned - although I’m not sure why a null value would be returned when adding instances of fields together ?

List all unmentioned files that link to file that holds this dataview query, which haven’t been mentioned yet in the textflow otherwise.
Great for quickly creating MOC files that automatically track and list all files that link to it

list from [[]] and -outgoing([[]]) sort file.name asc

Show all recently created files with outlinks and inlinks

table 
file.outlinks as "To", file.inlinks as "From"
from "" sort file.ctime desc

Show all uncreated files (Files that are being linked to in other files but haven’t been created yet) THX @mnvwvnm

TABLE without id 
out AS "Uncreated files"
FLATTEN file.outlinks as out
WHERE !(out.file) AND !contains(meta(out).path, "/")
GROUP by out
SORT out ASC

Show all Uncreated files with origin (Files that are being linked to in other files but haven’t been created yet). THX @mnvwvnm

TABLE without id 
out AS "Uncreated files", file.link as "Origin"
FLATTEN file.outlinks as out
WHERE !(out.file) AND !contains(meta(out).path, "/")
SORT out ASC

List all outlinks and inlinks of specific file with exclusion of the file that holds this dataview query. (I use it to preview links to and from MOC files one step down the hierarchy)
Files are beeing sorted in the order they appear as links in the flowtext

list from outgoing([[FILENAME]]) or [[FILENAME]] where file.link != [[]] sort file.links asc
4 Likes

Hi Moonbase59,

Great piece of work, thank you very much!

I’ve done some testing and was wondering:

Shouldn’t
date(today).month100+date(today).day = birthday.month100+birthday.day,(date(today)-birthday).year,(date(today)-birthday).year+1) as Turns

be:
date(today).month100+date(today).day <= birthday.month100+birthday.day,(date(today)-birthday).year,(date(today)-birthday).year+1) as Turns ?

BR

Great examples. There’s not many out there on link analysis. Your post is a treatise on inlinks and outlinks.

Is it possible to do the following:

I’d like to find all outgoing links that appear in all notes in a folder, group by outgoing links with a count for each sorted desc.

Cheers!

  • Anytime!

  • It is difficult to explain it.

  • You don’t need to correct any null value. All you need to do is use the correct solution.

  • It is recommended that you should use the Conclusion in the following document because it is the correct solution.

  • You could read the DQL10, DQL20 and DQL30.

  • You may understand what happens in the DQL20_debug_sum_cash_groupBy.

  • In fact, it is necessary to understand the importance of the Conclusion. If you do not use the Conclusion, some notes are not presented in the result.

  • How to sum up a number, null, or a list of non-groupBy(or groupBy) data with skipping the null value? PS.To sum up one or two fields

So I’ve come up with this first

TABLE file.inlinks as Inlinks, length(file.inlinks) as Sum, file.outlinks as Outlinks, length(file.outlinks) as Sum, sum(length(file.inlinks)+length(file.outlinks)) as Total
FROM "path/to/folder"
SORT sum(length(file.inlinks)+length(file.outlinks)) desc, file.mtime desc

This will sort files in a folder by total of Outlinks and Inlinks. But the list will be quite big.

TABLE length(file.inlinks) as Inlinks, length(file.outlinks) as Outlinks, sum(length(file.inlinks)+length(file.outlinks)) as Total
FROM "path/to/folder"
SORT sum(length(file.inlinks)+length(file.outlinks)) desc, file.mtime desc

this is shortened to just the amounts.

I couldn’t figure out how to achieve your specific request though. But this solution should also give you an idea of “what files in a folder are the busiest”. If that’s your goal :).

Hope it helps out a bit.

Cheers

2 Likes

Very cool. Thank you!

I’ll get some learning miles out of your effort.

Hi all, love the plugin! Hopefully this is a simple question, and I just haven’t learned how to fully use it yet. :slight_smile:

I use AidenLx’s Folder Note plugin which uses a note named the same as the folder that it’s in (see example layout below).

My goal is to just show a list of folders and contents, but not the foldernote itself (the folder who’s name is the same as the parent). Here’s what the actual file layout looks like on disk:

Notes/
  Notes.md <--------- (this is a folder note)
  Subject A/
    Subject A.md <--- (this is a folder note)
    Some topic related to Subject A.md
  Subject B/
    Subject B.md <--- (this is a folder note)
    Some topic related to Subject B.md

I write a dataview list query in my Notes foldernote like this:

LIST rows.file.link
FROM "Notes"
WHERE file.folder != this.file.folder
GROUP BY link(file.folder, file.name)

The current WHERE is just to filter out the Notes.md file and only show everything else in the Notes/ folder. So, that will render this in obsidian:

- Subject A
    - Subject A
    - Some topic related to Subject A
- Subject B
    - Subject B
    - Some topic related to Subject B

I’m trying to find a way to do something like WHERE rows.file.name != rows.parent.name or something similar.

Any ideas?

Topic

Summary
  • How to get the s_file_parent_name of a file? (DQL10)
  • How to get the parent_foldernote of a file? (DQL20)

Test

Summary
  • dataview: v0.5.46

input

Summary

dictionary files:

  • Location: “100_Project/02_dataview/Q83_FolderNote/Q83_test_data”

  • filename : Q83_test_data.md
---
Date: 1990-12-31
---

### this is a folder note



folder: 1990-03

  • filename : 1990-03.md
---
Date: 1990-03-31
---

### this is a folder note



  • filename : dic_19920301.md
---
Date: 1990-03-01
---

## input
### milestones
- [type:: "food"] [desc:: "breakfast"] [cost:: 10] #Test/d01 [[Note J]] , [[Note K]]
- [type:: "food"] [desc:: "breakfast"] [cost:: 20] #Test/d02  [[Note J]]



  • filename : dic_19900306.md
---
Date: 1990-03-06
---

## input
### milestones



folder: 1990-04

  • filename : 1990-04.md
---
Date: 1990-04-30
---

### this is a folder note



  • filename : dic_19900401.md
---
Date: 1990-04-01
---

## input
### tasks
- [ ] [type:: "food"] [desc:: "breakfast"] [cost:: 100] #Test/d01 [[Note P]] , [[Note Q]]
- [ ] [type:: "food"] [desc:: "breakfast"] [cost:: 200] #Test/d02  [[Note P]]



  • filename : dic_19900406.md
---
Date: 1990-04-06
---

## input
### tasks



folder: 1990-05

  • filename : 1990-05.md
---
Date: 1990-05-31
---

### this is a folder note




DQL10_get_the_file_parent_name_of_a_file_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10_get_the
_file_parent_name
_of_a_file
_and_LIST
file.folder:
a string
yes 1.To define a field variable s_file_parent_name
2.To filter by file.name
3.To group by a link
4.To display the result as a list
1.The “parent link” doesn’t link to the folder note itself.
2.The Regular Expression in the DQL10 is based on the DQL10 in the following topic.
- Solutions: by Justdoitcc

Notes

Summary

Q: What does the following DQL statement mean?

FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name

To get the s_file_parent_name of a file
  • In English: To define a field variable s_file_parent_name as the expression like regexreplace(file.folder, "^(.*/)(.+)$", "$2") by using FLATTEN
  • In other words: let s_file_parent_name = regexreplace(file.folder, "^(.*/)(.+)$", "$2");
For example
  • file.path: 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03/dic_19900301.md
  • file.folder: 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03
  • s_file_parent_name: 1990-03
  • file.name: dic_19900301
  • file.ext: md

The same codes: to filter by file.name

  • To filter the data by file.name where file.name is not equal to s_file_parent_name
Original Example10
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
WHERE file.name != s_file_parent_name
Another Example11
FLATTEN split(file.folder, "/")[length(split(file.folder, "/")) - 1] AS s_file_parent_name
WHERE file.name != s_file_parent_name

DQL10_get_the_file_parent_name_of_a_file_and_LIST

Summary_code
title: DQL10_get_the_file_parent_name_of_a_file_and_LIST =>1.To define a field variable `s_file_parent_name` 2.To filter by file.name 3.To group by a link 4.To display the result as a list
collapse: close
icon: 
color: 
```dataview
LIST rows.file.link
FROM "100_Project/02_dataview/Q83_FolderNote/Q83_test_data"

FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
WHERE file.name != s_file_parent_name

GROUP BY link(file.folder, s_file_parent_name)
```

Screenshots(DQL10)


DQL20_get_the_file_parent_name_of_a_file_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL20_get_the
_file_parent_name
_of_a_file
_and_LIST
file.folder:
a string
yes 1.To define a field variable s_file_parent_name
2.To define a field variable parent_foldernote
3.To filter by file.name
4.To group by a link
5.To display the result as a list
1.The “parent link” actually links to the folder note itself.
2.The DQL20 is based on the DQL10 and SeanWcom’s suggestion.

Notes

Summary

The same codes: To get the parent_foldernote of a file

  • Take the file dic_19900301.md for example.
    • file.path: 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03/dic_19900301.md
    • file.folder: 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03
    • file.name: dic_19900301
    • file.ext: md
Original Example20: The absolute path
the slice of DQL
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
FLATTEN file.folder + "/" + s_file_parent_name + ".md" AS parent_foldernote
the result
  • s_file_parent_name: 1990-03
  • parent_foldernote : 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03/1990-03.md
Original Example21: The absolute path
the slice of DQL
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$1$2/$2.md") AS parent_foldernote
the result
  • s_file_parent_name: 1990-03
  • parent_foldernote : 100_Project/02_dataview/Q83_FolderNote/Q83_test_data/1990-03/1990-03.md
Another Example22: The relative path
the slice of DQL
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
FLATTEN s_file_parent_name + "/" + s_file_parent_name + ".md" AS parent_foldernote
the result
  • s_file_parent_name: 1990-03
  • parent_foldernote : 1990-03/1990-03.md
Another Example23: The relative path
the slice of DQL
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2/$2.md") AS parent_foldernote
the result
  • s_file_parent_name: 1990-03
  • parent_foldernote : 1990-03/1990-03.md

DQL20_get_the_file_parent_name_of_a_file_and_LIST

Summary_code
title: DQL20_get_the_file_parent_name_of_a_file_and_LIST =>1.To define a field variable `s_file_parent_name` 2.To define a field variable `parent_foldernote` 3.To filter by file.name 4.To group by a link 5.To display the result as a list
collapse: close
icon: 
color: 
```dataview
LIST rows.file.link
FROM "100_Project/02_dataview/Q83_FolderNote/Q83_test_data"

FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
FLATTEN file.folder + "/" + s_file_parent_name + ".md" AS parent_foldernote

WHERE file.name != s_file_parent_name
GROUP BY link(parent_foldernote)
```

Screenshots(DQL20)

Part 1/2

Part 2/2


1 Like

Fantastic, thank you! Learning more and more Dataview every day! :slight_smile: Here’s what I ended up with:

LIST rows.file.link
FROM "Notes"
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2/$2.md") AS parent_foldernote
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS parent_name
WHERE file.name != parent_name
GROUP BY link(parent_foldernote)

This lets me be sure that the “parent link” is actually linking to the folder note itself. So adding a second variable lets me use both the parent folder name, and the foldernote name.

Thanks!!

2 Likes