Davtaview TABLE query on Tasks

Hi,

For the last days I have been struggling with – what I thought – would be a simple query within Dataview with the Tasks Plugin; however, I do not make it work and are in desperate need of help :wink:

What I’m trying to do

I run a dataview query over a list of tasks and would like to exclude those tasks that are completed - pretty simple ask, I thought.

What I have tried

This is the list of tasks from “Notes/Tasks”

  • [x] Task #1 :flight_departure: 2023-02-27 :hourglass_flowing_sand: 2023-02-27 :date: 2023-02-28 :white_check_mark: 2023-02-27
  • [ ] Task #2 :date: 2023-03-05 :flight_departure: 2023-02-28
  • [ ] Task #3 :date: 2023-02-28 :flight_departure: 2023-02-27 :hourglass_flowing_sand: 2023-02-27
  • [ ] Task #4 :date: 2023-03-10 :flight_departure: 2023-03-06 :hourglass_flowing_sand: 2023-03-07 :arrow_double_up:

… and this is the query:

TABLE WITHOUT ID regexreplace(Tasks.text, "((([📅⏳🛫⏫🔼🔽].*|\<.*)\n*$))", "") AS Task, file.link AS "File", Tasks.due AS "Due Date"
FROM "Notes/Tasks"
FLATTEN file.tasks AS Tasks
WHERE (status != "x") AND (status != "X")

This does not work :frowning:
I have replaced the WHERE clause with various options:

  • WHERE !completed (shows all tasks)
  • WHERE status = !completed (shows no task at all)

If I am using the Dataview TASK query, it works perfectly:

TASK
FROM "Notes/Tasks"
WHERE !completed

However,
(1) I would like to have table set up and (more importantly)
(2) I am not a big fan of color icons, icons at all (I like a very plain, minimalistic setup) - and I did not find a way to include the regexreplace option in the TASK query.

After all, I would think that the TABLE query option should also work, and it is certainly me, making some mistakes in the query :wink: So I am in need of some hints on what I am doing wrong here!

Thanks!

Sven

I wanted to build a table from tasks like that, too, but going by the documentation, it’s not possible. From the Query Type > Tasks description:

TASK queries are special compared to the other Query Types because they do give back Tasks as results and not pages.

So with a Table query view you can only build a list of pages.

Thanks!

So with a Table query view you can only build a list of pages.

Right, which is precisely what I want to do :wink:
However, I would rather not show those tasks that have already been completed (or cancelled).

You can use FLATTEN to change tasks into rows so that you can use them in a table. Try something like this:

```dataview
TABLE Task.text as "Task Text"
FROM "Inbox/Dataview Task Test"
FLATTEN file.tasks as Task
WHERE !Task.completed
```

You’ll need to change the FROM statement for your vault, of course.

Here’s what it looks like in my vault:

Thanks, Craig!
I was missing the syntax

WHERE !Task.completed

That works now - thanks a lot!

1 Like

As you’ve discovered already, you were almost there, just missing the Tasks.status instead of just status in your original query. So that base is covered. However, I’m here to address the way to include the regexreplace option in the TASK query.

It can actually be done, but it’s not very intuitive, at first, how to do it, so here is the query:

```dataview
TASK
FROM "Notes/Tasks"
FLATTEN regexreplace(text, "((([📅⏳🛫⏫🔼🔽].*|\<.*)\n*$))", "") as visual
```

The trick is to use FLATTEN regexreplace(text, ...) as visual. This allows us to change the text of the tasks, whilst still keeping the reference to the original task text (which again is needed to be able to complete the task).

( This trick can also be applied if working with the tasks within dataviewjs, and then you can present the tasks within table format, with some consistency and still allow for them to be completed. This trick
has been used to replace the text with a span having different color depending on due dates, and so on. )

Sadly enough, I wasn’t able to use this trick within a TABLE query, as I’m not able to alias the replacement into Tasks.visual or `Tasks[“visual”].

Finally, a word of caution, your regex will work in most cases, as long as you don’t add any text after the icon parts, so don’t be surprised if you in some cases might loose the rest of the text using this regex. It would be safer to use some regex limited to the actual date following the various icons. Your regex also eliminates any html-tag (or anything starting with \n), with the same caveat, but I reckon it’s there for a reason?

1 Like

That is so cool! I didn’t even think about adding the regex into the FLATTEN element and using it as a visual – absolutely great! I will look into dataviewjs to get the table format while having the ability to complete the tasks – that is actually what I would like to have.

Regarding your word of caution: I can easily imagine that – it is the first time I have been using Regex and I just scratched on the surface. I will take a closer look and try to realize your comments because it is not there for a reason, just lacking expertise. :wink:

Oh that’s cool. I didn’t know about the “visual” trick – is that in the docs anywhere?

It’s listed in the Metadata list for tasks, see Metadata on Tasks and Lists - Dataview

But there isn’t a lot of examples showing the magnitude of options this opens up for.

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