Tag variable in Tasks Dataview

What I’m trying to do

I am trying to use Dataview to query tasks that have a particular tag. I’d like to be able to use “this.file.etags”. I want to do this so the MOCs I create can include associated tasks based on tags defined in the header.

Things I have tried

I’m able to make this work with the hardcoded tag in the Dataview query (tags include #specificTag).

So what happens in your current query, and what do you expect it to do? Your explanation is a little diffuse.

The this.file.etags will list all of the tags for the current file. Do you really want to use that?

A task doesn’t have etags associated with it directly, just tags, but that shouldn’t pose as a problem since they are both holding tags, (and the task variant doesn’t expose the various sub-tags like the file.tags does).

Lastly, if you actually want to do a tag comparison between two different list of tags, you need to do something like the following:

filter(tags, (t) => contains(file.etags, tag))

And depending on your use case, you might need to do a map() instead of the filter in combination with with all( ... ) or any( ... ) surrounding the filter(). And depending on which list needs to be matched against the other you might need to switch around the tags and file.etags.

In short, a little more information would be useful. E.g. with a typical MOC entry of tags, and some tasks corresponding to those MOC headers. And your current query, faulty or not.

I’d like for the query to be more dynamic than it currently is. For reasons unknown to me, the tasks plugin does not seem to support what I’d like to do.

My goals is for my tasks to include tags that are associated with my MOCs. I’d like for this to updated dynamically instead of going into the query to update the tag.

This works

tags include #specificTag

This does not

tags include this.file.etags

The reasons it doesn’t work is that you’re mixing code related to Dataview queries and Tasks queries. They don’t intermingle. You need to do all of your query in one or the other.

More specific the this.file.etags is a DQL query expression, which can’t be used in a Tasks query, and I don’t think there exists an alternative as I don’t think Tasks queries are aware of any inline fields (besides its own status variant).

This means that to achieve your goal, one way forward could be to rewrite your Tasks query into a Dataview task query, and then accomplish your end goal doing some variation over what I wrote in my previous reply.

Since I don’t know the query you’re currently using, I can’t write you an example of what this would look like. In general most Tasks queries can be rewritten into dataview queries, but you’ll loose the recurrence functionality when completing tasks (through a dataview query), and the syntax is rather different.

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.

Thank you for your help with this. I do admit I’m not explaining this well.

I was able to create what I want with the query below, I’m just not able to group by due date. Any suggestions would be appreciated, otherwise I’ll move on.

where any(contains(text,this.file.etags))

I’ve fiddled with it more and came to the following solution. Generally get’s me the same view I’m getting with the task query.

where any(contains(text,this.file.etags)) and due >= date(2023-02-01) and due <= date(today)
group by due 

Task Query

group by due date
tags include #specificTag
sort by description asc

Note your solution depends on this.file.etags to contains exactly one tag, and that it’ll break if you introduce multiple tags into that field. If you never will match against more than one tag, you’re good to go, but if you need to (at some point) match against multiple tags, you need to look into some solution like the one I’m talking about in the post below:

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