Struggling To Filter Metadata Which Is Sometimes Not An Array, And Removing Duplicates

Hello friends. I am incrementing my Vault to its next level. Currently I have #Daily notes which serve as my daily journal fo what I’m up to.

When I work on a Project, I add Project metadata to that Daily note, which links to the relevant #Project note. Furthermore, when I work on a Task, I also add Task metadata, which links to the relevant #Task note. Most #Task notes also have Project metadata, so a #Task can belong to a particular #Project. Often I’ll work on several Projects and Tasks in a day.

I am trying to improve my Project notes to be more informative. Currently they list what days I worked on that Project. I’m trying to make it into a table such that which Tasks I worked on on each day are also displayed, but only those relevant to this Project note.

This was my naive first attempt to get me started:

TABLE WITHOUT ID

file.link AS Date,

task AS Tasks

FROM #Daily AND -"99 Templates" AND -"98 Experiments"
WHERE contains(project, [[]])
SORT file.day DESC 

It has two issues.

  1. When listing the Tasks, the query is too broad and gets all the Tasks I worked on regardless of whether they belong to this Project.
  2. On some days I worked on a Task, did something else, and came back and worked on it again. I link to the Task each time I start working on it again, so my Daily notes better reflect my flow of activities. This causes the Task notes to appear twice in the Task list however, and is duplicated in the above query.

The second issue I have no idea about solving. I’ve tried reading the documentation about flattening and grouping but cannot understand it.

The first issue I’m surprised I can’t solve. I knew my naive approach would behave like that, but I’m surprised at the behaviour of my attempted fix. I tried replacing the naive task AS Tasks with this block:

filter(task, (x) => x.project = [[]])
AS Tasks

This does work to remove the Tasks which don’t belong to this Project, but only for days in which I worked on multiple Tasks. If a Daily note only has one link in its task metadata, it no longer shows up in the query at all. This happens even if that one Task does belong to this Project. As a result, the total number of days tabled goes from 20 to 11.

It surprises me that making this change is changing the number of items queried, as I thought that was solely handled by the FROM and WHERE commands.

My next thought was that maybe this part of the query errors, and thus they don’t get returned. I understand that filter() takes an array as input, but when the task metadata has just one link, the task metadata is of type link instead of array. I’ve tried using choice() and typeof() to change the behaviour in that case, but it didn’t work.


I’d appreciate any help from a Dataview Wizard to get this query behaving as I want. Thanks! :slight_smile:

Solved!

So I was able to solve both of these issues.

In my OP, I tried to get just the tasks relevant to this Project note by filtering down the task metadata on each #Daily note. Instead I came at the tasks from a different approach. I instead started with a list of all the #Task notes which have this note as their project, and then I filtered that list to those that were worked on on the given day in the table:

filter(
	this.file.inlinks, 
	(x) => 
		econtains(x.file.etags, "#Task") 
		AND x.project = [[]] 
		AND contains(x.file.inlinks, file.link)
)
AS "Tasks" 

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