Dataview plugin snippet showcase

Perfect!

Here is the result - I like how it returns both “tool/*” and “tools” - exactly what I wanted.

5 Likes

Hey Dug, another elegant solution!

Is it possible to tweak this further to filter out notes without any assigned task?

paoloap, if you want to only show notes that have tasks associated with them, then you can add a WHERE clause to the query:

```dataview
TABLE
		join(choice(file.tasks.completed, "●", "○"), "") as status
FROM
		#current_project
WHERE
		file.tasks
```

This will only return notes that have tasks in them.

Should you need to find notes that don’t have tasks in the future, you can negate the WHERE clause as follows:

WHERE
    !file.tasks

The ! character means not, so you’re looking for note where there is not any tasks.

3 Likes

This is something I recently discovered, but an empty [[]] queries for pages linked to the current note:

list from [[]]
sort file.name asc
6 Likes

Aggregating all of my tasks into one note, sorted in a descending manner.

'''dataviewjs
dv.taskList(dv.pages().file.tasks
.where(t => !t.completed).sort(t => t.path, 'desc'))
'''
4 Likes

Absoloutly perfect!

1 Like

So I’ve just started using Dataview and discovered it has a Calendar display, and I’d like to use it to fetch a metadata field from daily notes and add it to that day in the calendar. I can do it, but what I can’t do is style the dots that appear in the calendar.

I want to have an “activities” field for each day which can have one or more activities, and then have a color coded dot or a symbol in the calendar for that day. Sort of what this plugin does GitHub - duoani/obsidian-habit-tracker: This plguin for Obsidian creates a simple month view for visualizing your punch records. but pulling it from within each daily note.

Is there any way to do this?

Quick update on my task aggregator, which is updated to ignore a specific page (ignore tasks in my Media note):

'''dataviewjs
dv.taskList(dv.pages().file
  .where(f => f.name != "Media")
  .tasks
  .where(t => !t.completed)
  .sort(t => t.path, 'desc'))
'''
4 Likes

How do I always round down with Dataview? I’m calculating age with an inline field. Floor does not work.

= round((date(today) - this.Dob).years)

Try the following to see it it works for you:

`= round((date(today) - this.Dob).years - 0.5)`

This should be similar to how floor() works. You could add 0.5 to replicate ceil().

4 Likes

Works great, I was overthinking it, thanks!

Looking at this, it should be possible to search for parts of link titles. I have files named “1st Karlovy Vary IFF”, “2nd Karlovy Vary IFF”, etc. I want to list all notes linking to any of these by searching for “Karlovy Vary IFF” in a link. But this doesn’t work:

LIST
WHERE contains(file.outlinks, "Karlovy Vary IFF")

Why doesn’t this work? Can I only do this with dataviewjs?
Thanks!

@erazlogo, I was happy to explore this for you. You have already looked for the out links of the file, but now you need to say “only if its file name contains this text…”

file.outlinks.file.name

2 Likes

@dryice Amazing, it works! Thank you so much!

1 Like

Hi there!
I am pretty new to Dataview and an absolute noob in JS, but I’m trying to create a time estimator in my “TO DO now” Kanban board.
Here is the example with Kanban board:

I implement here inline field annotation of tasks with =sum(filter(this.file.tasks.estimated_time, (p) => p)) to calculate time across ALL tasks with estimated_time field in the Kanban board.
But the problem is when I archive my old tasks → time from that tasks is still in use.
I’ve tried to filter field extraction according to section or header, but I’ve got no result. Usual field extraction by =this.estiamted_time also doesn’t work.
Maybe someone has genius ideas about it?

1 Like

I am trying to accomplish something similar with my goal planning and projects execution.

My “goals” would correspond to the level of “year”, and “project” to “quarter”. In the goal YAML I included the project as a link to the note, as you do with quarters. The result renders the name of the project but not the link, ie. it’s not clickable. Can you please help me understand what need to be fixed?

Thanks, appreciate you sharing this set-up, it really clicks with how my brain works :slight_smile:

Have noticed that for the keys written with spaces in YAML, dataview cannot return results:

In the YAML sample, the key note type and MOC area have spaces

---
version: 1.00
title: Dataview manual
note type: tools for Obsidian
MOC area: Obsidian
cdate: 2022-02-15

tags: 
  - dataview
  - plugin
  - manual
---

If to change them to note_type and MOC_area have spaces, dataview works as desired.
Or am I doing something wrong?

In the hope that this helps…

Angel

2 Likes

Thanks you - works now)))!

1 Like

In order to easily reference which programming problems cover which topics I wrote this. It can easily be used for anything else by changing the filter tags. You can also get rid of the following :

  let include = new Set([
    "BFS","DFS","Recursion","Tree","Trie","Graph","Heap","Array","HashMap",
    "Set","LinkedList","GhostNodes","Sorting","SlidingWindow","Backtracking",
    "TopologicalSort","DP","TreeTraversal","BinarySearch"
  ].map((x) => `#${x}`));
tagMap.forEach((v, k) => {
    if (!include.has(k))
      tagMap.delete(k);
  });

If you want it to make tables for any tag.
Heres the snippet:

` ``dataviewjs
  var _a;
  let filtertags = ["programming", "problem"];
  let include = new Set([
    "BFS","DFS","Recursion","Tree","Trie","Graph","Heap","Array","HashMap",
    "Set","LinkedList","GhostNodes","Sorting","SlidingWindow","Backtracking",
    "TopologicalSort","DP","TreeTraversal","BinarySearch"
  ].map((x) => `#${x}`));
  let source = filtertags.map((tag) => `#${tag}`).join(" AND ");
  let files = dv.pages(`${source} AND -"00 Meta/06 Templates"`).map((p) => p.file);
  let tagMap = new Map();
  for (let page of files)
    for (let tag of page.tags) {
      let data = (_a = tagMap.get(tag)) != null ? _a : { tagnum: 0, pages: [] };
      data.tagnum++;
      data.pages.push(page);
      tagMap.set(tag, data);
    }
  filtertags.forEach((t) => tagMap.delete(`#${t}`));
  tagMap.forEach((v, k) => {
    if (!include.has(k))
      tagMap.delete(k);
  });
  let count = 1;
  let headers = [];
  let elements = [];
  let sorted = Array.from(tagMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
  for (let [tag, data] of sorted) {
    headers.push(`${tag.replace("#", "")} (${data.tagnum})`);
    elements.push(data.pages.map((p) => p.link));
    if (count++ % 3 == 0) {
      dv.table(headers, [elements]);
      headers = [], elements = [];
    }
  }
  if (headers.length > 0)
    dv.table(headers, [elements]);
` ``
5 Likes