Filtering out files that are linked to on current page in dataview

What I’m trying to do

Context: My daily note has a section that lists all incompleted tasks in Dataview, along with a section for high priority tasks where I manually drag a link to a task from the Dataview table.

The current behavior is the task showing up in two locations (high priority section and the Dataview table)

The desired behavior is for the Dataview to filter out a “high priority section” link once I drag it to that section, so that the same task doesn’t show up in two spots on my daily note.


Things I have tried

I’ve tried using the answers to this discussion as reference, but the filters I’ve tried don’t work.

I’d really appreciate any help!! Thanks!

I’m a little confused by your wording, what constitutes as a task in your world? Just a file tagged with #task?

If so, and you want to remove links/tasks(?) from the current file can’t you use file != this.file as and added WHERE clause? Or is there other links/tasks you’ll want to preserve from the current file?

Thanks for responding! yep, the tasks are files with a task tag in the yaml frontmatter.

file!=this.file doesn’t work by the way when I tested. The page with the dataview table/priority list is not a task; it’s a daily note that has outgoing links to some tasks (these are the links that I don’t want showing up in my dataview table)

OK, so your main tasks are note files, and in your current you’ve got links to these files which if present you want removed from the global list.

Firstly, in order to do any filtering on the tasks links from any given section in the current file we need to do the following magic:

 FLATTEN
  list(
    filter(
       this.file.tasks, 
       (t) => meta(t.section).subpath = "PO Tasks"
  )) as PO_Tasks

This does the following:

  • FLATTEN ... as PO_Tasks – Whatever expression follows the “…”, is stored into PO_Tasks for subsequent handling
  • list( ... ) – The next expression will be treted as a list (and not expanded into its separate items as is the default for FLATTEN )
  • filter( this.file.tasks, (t) => ... ) – The filter() function will return any elements of the list is given (aka this.file.tasks) where each element, t, is matched against the next expression
  • meta(t.section).subpath = "PO Tasks" – From a given task, we lift out the section link, and using meta() we look at its components, and in particular the subpath element which holds the actual heading text

So all in all, this rather lengthy snippet pulls out the list of tasks that are in the “PO Tasks” section of the current file.

But you didn’t want that list, but to exclude all links from that list to be excluded from the overall list of files matching your query, and that is achieved by doing:

  WHERE !contains(PO_Tasks.outlinks, file.link)

We don’t want to include any file’s link which matches any links in the prioritised task list.

Using both of these we’ll end with the following query:

```dataview
TABLE due-date as "Due"
FROM (#task or #exam) and #obsidian_forum_example
FLATTEN list( filter( this.file.tasks, (t) => meta(t.section).subpath = "PO Tasks" )) as PO_Tasks
WHERE !contains(PO_Tasks.outlinks, file.link)
WHERE complete = "no"
SORT due-date ASC
LIMIT 10
```

Hopefully that should work according to your specifications! :smiley:

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks or queries) is properly shown.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.