# DataView
[Query Builder](https://s-blu.github.io/basic-dataview-query-builder/)
[Official Reference](https://blacksmithgu.github.io/obsidian-dataview/)
### Examples
start all with " \`\`\` dataview"
via [[ToDo List]]
```
TASK
from ""
WHERE !contains(text,"#hold") and !checked and !ignore-tasks = true
GROUP by file.name
Sort file.mday
```
via [[Meal Planning]]
```
table without ID link(file.link, file.name) AS "Recipe"
FROM "Food/Recipes"
```
via [[Stimulant]]
```
Table Medication_CommonBrand as "Brand Name"
Where contains(Type,"Medication") and contains(fileClass,"Chemical") and contains(Medication_Class,"Stimulant")
Sort file.name ASC
```
via [[Home Search]]
```
table without ID
link(file.link, Address) as Address,Cost, Beds, Baths, Size
where location
```
### Basic Outline of a Query
```
```dataview
[Query Type] [without ID] [additional information]
[FROM]
[WHERE, SORT, GROUP BY, FLATTEN, LIMIT]
```
Query Type: `LIST`, `TABLE`, `TASK` and `CALENDAR` (Only Required info)
additional information:
- for lists, only 1 additional info
- ex. `"File Path: " + file.folder + " _(created: " + file.cday + ")_"`
- for tables, can have custom headings using `as`
- ex. `file.folder AS Path, file.etags AS "File Tags"`
- can use [functions](https://blacksmithgu.github.io/obsidian-dataview/reference/functions/) calculations or expressions, ex. `default(finished, date(today)) - started AS "Played for"`
some example functions:
- `meta()` [Link](https://blacksmithgu.github.io/obsidian-dataview/reference/functions/#metalink)
### In-Line Queries
[More Info](https://blacksmithgu.github.io/obsidian-dataview/queries/dql-js-inline/)
```
`= this.file.name`
`= this.file.mtime`
`= this.someMetadataField`
`= [[secondPage]].file.name`
`= [[secondPage]].file.mtime`
`= [[secondPage]].someMetadataField`
```
### High Level Summary of Expressions
```
# Literals
1 (number)
true/false (boolean)
"text" (text)
date(2021-04-18) (date)
dur(1 day) (duration)
[[Link]] (link)
[1, 2, 3] (list)
{ a: 1, b: 2 } (object)
# Lambdas
(x1, x2) => ... (lambda)
# References
field (directly refer to a field)
simple-field (refer to fields with spaces/punctuation in them like "Simple Field!")
a.b (if a is an object, retrieve field named 'b')
a[expr] (if a is an object or array, retrieve field with name specified by expression 'expr')
f(a, b, ...) (call a function called `f` on arguments a, b, ...)
# Arithmetic
a + b (addition)
a - b (subtraction)
a * b (multiplication)
a / b (division)
a % b (modulo / remainder of division)
# Comparison
a > b (check if a is greater than b)
a < b (check if a is less than b)
a = b (check if a equals b)
a != b (check if a does not equal b)
a <= b (check if a is less than or equal to b)
a >= b (check if a is greater than or equal to b)
# Strings
a + b (string concatenation)
a * num (repeat string <num> times)
# Special Operations
[[Link]].value (fetch `value` from page `Link`)
```
## Functions
[more info on functions](https://blacksmithgu.github.io/obsidian-dataview/reference/functions/)
```
replace("yes", "e", "a") = "yas"
replace(["yes", "ree"], "e", "a") = ["yas", "raa"]
link("Hello") => link to page named 'Hello'
link("Hello", "Goodbye") => link to page named 'Hello', displays as 'Goodbye'
contains("Hello", "Lo") = false
contains("Hello", "lo") = true
icontains("Hello", "Lo") = true
icontains("Hello", "lo") = true
econtains("Hello", "Lo") = false
econtains("Hello", "lo") = true
econtains(["this","is","example"], "ex") = false
econtains(["this","is","example"], "is") = true
```
[Click here for additional information on functions](https://blacksmithgu.github.io/obsidian-dataview/reference/functions/)
#### Constructors - create values
```
object(key1, value1,...)
list(value1, value2, ...)
date(any)
date(text, format)
dur(any)
number(string)
string(any)
link(path, [display])
embed(link,[embed?])
elink(url,[display])
typeof(any)
```
#### Numeric Operations
```
round(number, [digits])
min(a,b,...)
max(a,b,...)
sum(array)
product(array)
average(array)
minby(array, function)
maxby(array, function)
```
#### Objects, Arrays, and String Operations
```
contains()
icontains() %%case insensitive%%
econtains() %%exactly contains%%
containsword(list|string, value)
extract(object, key1, key2, ...)
sort(list)
revers(list)
length(object|array)
nonnull(array)
all(array)
any(array)
none(array)
join(array, [delimiter])
filter(array, predicate)
map(array, func)
flat(array, [depth])
```
#### String Operations
```
regextest(pattern, string)
regexmatch(pattern, string)
regexreplace(string, pattern, replacement)
replace(string, patttern, replacement)
lower(string)
upper(string)
split(string, delimeter, [limit])
startswith(string, prefix)
endswith(string, suffix)
padleft(string, length, [padding])
padright(string, length [padding])
substring(string, start, [end])
truncate(string, length, [suffix])
```
#### Utility Functions
```
default(field, value)
choice(bool, left, right)
striptime(date)
dateformat(date|datetime, string)
localtime(date)
meta(link)
```
## Tables
>[!info] Metadata names are case-sensative
### How to sort by multiple fields
```
SORT columnA ASC, columnB ASC
```
### How to include an image
using ImageUrl in metadata
```
"" As Image
```
### How to omit the File Name
```
Table without ID
```
### How to link to the page
```
link(file.link, title) AS "Title"
```
## Inline Fields
Use the double ":" to put a field anywhere besides the frontmatter.
Use brackets for different formatting.
Use parenthesis to hide the field name.
```
Field:: value
[Field2:: value2]
(Field3:: value3)
```
## Implicit Fields
DataView will automatically have some fields for every file.
![[Implicit Fields from DataView]]
___
## See Also
[[Obsidian]]
[[Implicit Fields from DataView]]