#### [[Obsidian Plugin DataView]]
---
````
```dataview
[list|table|task] field1, (field2 + field3) as myfield, ..., fieldN
from #tag or "folder" or [[link]] or outgoing([[link]])
where field [>|>=|<|<=|=|&|'|'] [field2|literal value] (and field2 ...) (or field3...)
sort field [ascending|descending|asc|desc] (ascending is implied if not provided)
```
````
### Views
#### Table
%%
```dataview
table tags
from outgoing([[ADHD]])
```
%%
#### List
%%
```dataview
list tags
from outgoing([[ADHD]])
```
%%
#### task
%%
```dataview
task
from ""
where file.name = "✏️ Workbench"
```
%%
### Fields
%%
aliases, tags, file.size, file.ctime, file.mtime, aliases.data
%%
%%
```dataview
table file.name
from ""
where file.name = "✏️ Workbench"
sort file.mtime desc
```
%%
### Where
%%
```dataview
table aliases, tags, file.size, file.ctime, file.mtime
from outgoing([[ADHD]])
where file.mtime.day > 6
sort file.mtime desc
```
%%
can use *where not null* through: `where (field) != NULL`
### Sort
%%
```dataview
table tags, file.ctime.year as Y, file.ctime.month as M, file.ctime.day as D
from ""
sort file.ctime.year asc, file.ctime.month desc, file.ctime.day asc
```
%%
## Viewer contribution
%%
The dataview code to generate this is:
```dataviewjs
//holds map of concepts to array containing [count, array of pages]
var cmap={};
//expects pages to have attributes listing linked concepts
//ie
//Concepts:: [[Management]],[[Leadership]]
//create groups of pages containing each set of concepts
//eg if two pages have the line above, this will be one group
for(let group of dv.pages('').groupBy(p=>p.Concepts)) {
if (group.key!=null) {
// loop through each concept and count pages, build sets of lins
for (var i = 0; i < group.key.length; i++) {
var concept=group.key[i];
if (cmap[concept]==null)
//first time we've seen this concept. Set count to 1, store links
cmap[concept]=[1,group.rows.file.link];
else
// we've seen this before. Add new count to count. Add links to existing array of links
cmap[concept]=[cmap[concept][0]+1,[...cmap[concept][1], ...group.rows.file.link]];
}
}
}
var tuples = [];
//turn the map into an array of arrays, with each element being
//[concept,count,pages]
for (var key in cmap) tuples.push([key, cmap[key][0]]);
//sory by count
tuples.sort(function(a, b) {
return a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0
});
//table it up!
dv.table(["Concept", "Count"], tuples);
```
Or you can include a version that includes links:
```dataviewjs
//holds map of concepts to array containing [count, array of pages]
var cmap={};
//expects pages to have attributes with comma separated list of linked concepts
//ie
//Concepts:: [[Management]],[[Leadership]]
//create groups of pages containing each set of concepts
//eg if two pages have the line above, this will be one group
for(let group of dv.pages('').groupBy(p=>p.Concepts)) {
if (group.key!=null) {
// loop through each concept and count pages, build sets of lins
for (var i = 0; i < group.key.length; i++) {
var concept=group.key[i];
if (cmap[concept]==null)
//first time we've seen this concept. Set count to 1, store links
cmap[concept]=[1,group.rows.file.link];
else
// we've seen this before. Add new count to count. Add links to existing array of links
cmap[concept]=[cmap[concept][0]+1,[...cmap[concept][1], ...group.rows.file.link]];
}
}
}
var tuples = [];
//turn the map into an array of arrays, with each element being
//[concept,count,pages]
for (var key in cmap) tuples.push([key, cmap[key][0],cmap[key][1]]);
//sory by count
tuples.sort(function(a, b) {
return a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0
});
//table it up!
dv.table(["Concept", "Count", "Pages"], tuples);
```
Index of All Tags ( Listed as Table )
```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags,
link(sort(rows.file.name)) AS Files
FROM #🧠️/✅️
WHERE file.tags
FLATTEN file.tags AS tag
GROUP BY tag
SORT file.name ASC
```
```dataview
LIST
" <br/><span style='color: #689d6a;'>|</span> <small>*Modified: "+file.mtime+"*</small>
<span style='color: #689d6a;'>|</span> <small>Created: "+file.ctime+"</small>"
FROM ""
WHERE file.name != this.file.name
WHERE !contains(file.name, "🏷")
SORT file.mtime DESC LIMIT 15
```
%%
---
Tags:
Reference:
Related:
-