They Are Called Dataview Literals

And I like using Them!

Posted by Amina Delali on February 02, 2024 · 4 mins read

What Are Dataview Literals

You can find their official definition from the Dataview Documentation website, but this is how I am going to describe them: they are the values that you use inside your Dataview query, and that have no related data. As a reminder, the data is the information extracted from your notes frontmatter, your inline fields, and your notes implicit fields.

For example, values represented in the form of numbers, text, or dates are literals:

  Literal Examples
 “This a Text”
 date (2024-02-02)

In the example above, a date function was used to generate a literal Date Object

How Are They Used

Imagine you have to extract all the notes that their names contain the word “Definition”. So you will use the literal “Definition” that is of type String. As you may notice, the word “Definition” doesn’t refer to any particular data from the notes.

So, you can simply write the following query:

where contains(, "Definition")

Here, I used the literal inside the Dataview function contains.

There are different types of literals that you can use in your queries:

 Dataview Literals    Example     Meaning  
 Numbers   65  The number 65
 Text   “This is actually a String”   The text “This is actually as String”
 Links   [[This is a Note]]   A link to the note: This is a Note
 List   [“word”, “letter”, “phrase”]   A list containing 3 string elements
 Objects   {key1: 5 , key2: “A Test” }   An object with 2 keys (key1 and key2) and their corresponding values
 Dates  date (today)  The date of today
 Durations  dur (3 m)   3 Minutes duration

In the table above, two different functions where used: date and dur to genereate two different types of literals: date and duration respectively.

The detailed list of literals and their possible values can be found in the Dataview Literal Documentation Page

This How I used Them

In my daily note, I wanted to automatically highlight the due tasks with a specific indicator that is corresponding to their due dates. So first, I list only the tasks that are due before or at the note’s date, and I group them by their due dates. Then, according to how far the due date of these tasks is from today’s date , a colored square emoji is added to corresponding group:

🟩: they are due at or after the today’s date (the today’s date can be different from the note’s date).
🟨: they are due 1 day or more than 1 day before the today’s date. But, less than 3 days.
🟧: they are due 3 days more than 3 days before the today’s date. But, less than 7 days.
🟥: they are due 7 days or more than 7 days before the today’s date.

The use of dataview literals example

Of course, I used other literals to add other indicator, specifically related to my Obsidian vault, as well as to specify the folder from which to extract these tasks.

Here is the entire Dataview query that I am using right now:

task from "Execute/Projects" where !completed 
and due <= date(
sort time  asc
sort due asc
group by  dateformat(due,"yyyy-MM-dd EEEE") +" " + truncate(substring(,4),30)+" "+file.tags[0]+ choice(file.frontmatter.status[0]="progress"," 🧩","") +
choice(contains(file.folder,"Support")," 🧰",choice(contains(file.folder,"Action")," 🎬"," 📖"))+" "+
choice(date(today)-due>=dur("7 days"),"🟥", choice( date(today)-due>=dur("3 days")  ,"🟧",choice(date(today)-due>=dur("1 days") ,"🟨", "🟩" )  ))

And here an extract of the result:

The use of Dataview Literals Results