Dataviewer - Table Headers From Tasks Under A Header

Hi all,

I feel a bit silly for not being able to figure this out on my own but I’ve been trying to figure this out for a bit over an hour now and can’t quite get it!

I have a daily note with daily tasks that I would like to summarise in a table. My daily tasks are found in the following directory To-Do/Daily To-Dos/, the daily tasks section is as below. The daily note is named in the yyyy-mm-dd format.

# 📅 Daily Tasks

- [ ] Journal 
- [ ] Brush teeth
- [ ] 5,000 steps (check Paseo)

I would like to make a dataview table in a separate note that has a header for each of these tasks and for the file name but I can’t figure out how! I’ve read through the docs on dataview fields and implicit fields but I can’t find a clean way (without inserting maybe a tag or something to each task) to do this.

Can anyone offer some advice? Hopefully this will be helpful to others too as I can’t be the only one struggling with this!

I don’t quite get what you mean here. “A header for each of these task”? Are the tasks identical in all the files, and do you want to group them by task? And if so, then what do you mean with “and for the file name”?

Are you simply wanting to extract this section from each daily note, and show all of them on this particular page? Or do you want to sum them up somehow, like a habit tracker?

And finally, do you have any other tasks on your daily notes, or are these three tasks always the only tasks on any given daily notes? (If not, you’ll need to tag these somehow (or do some magic related to them being under a given header, or similar).

So please provide more information, we’re not mind readers, even though many posters seem to believe so.

1 Like

I’m sorry that I wasn’t clear enough, allow me to elaborate. I’d like to make a table that looks like the below (albeit in a dataview table and not a more standard markdown table). Summed up like a habit tracker, as you mentioned.

| Filename   | Journal Task | Brushed Teeth Task | 5000 Steps Task  |
|------------|--------------|--------------------|------------------|
| 2023-01-16 | Complete     | Complete           | Null (or failed) |
|            |              |                    |                  |
|            |              |                    |                  |

This table should pull data from the daily notes located in the To-Do/Daily To-Dos/ directory, specifically this section below.

# 📅 Daily Tasks

- [ ] Journal 
- [ ] Brush teeth
- [ ] 5,000 steps (check Paseo)

There are other tasks in my daily notes, so yeah I’m looking for that mentioned “magic,” that they’re under a certain header. Or tagging them in a way that’s not distracting when just viewing them.

Does this clear up what I’m asking? Would anyone know how I could do this?

Yes, and yes. Much better!

Would the following suffice in some variant for you?

```dataview
TABLE
  journal.status as "Journal", 
  teeth.status as "Teeth", 
  steps.status as "Steps",
  tJournal, tTeeth, tSteps
FROM "To-Do/Daily To-Dos"
FLATTEN filter(file.tasks, (t) => t.text = "Journal") as journal
FLATTEN filter(file.tasks, (t) => t.text = "Brush teeth") as teeth
FLATTEN filter(file.tasks, (t) => t.text = "5,000 steps (check Paseo)") as steps
FLATTEN choice(journal.status = "x", "Written", " ") as tJournal
FLATTEN choice(teeth.status = "x", "Brushed", " ") as tTeeth
FLATTEN choice(steps.status = "x", "Walked", "Null (or failed)") as tSteps

SORT file.name
```

Adapt and change column titles, text to whatever you feel like! :smiley:

In my test setup this returned:

Disclaimer: This solution is very dependent on you not changing the text in any ways, as that would break the logic. It would be safer using tags, or other mechanism for marking the tasks. Text matching is volatile by nature.

2 Likes

Hey, sorry for the mega late reply here!

Thank you so much for getting back to me, this is super helpful. After seeing what this can do I’m more interested in learning DQL, I feel like I could neatly keep track of so many things!

This is really close to what I need but because I use the Tasks plugin it marks a :white_check_mark: and the date when I finished a task after I’ve completed a task which seems to mess up this dataview query.

Ex: below is a copy of what your query looks like when plugged into my vault.

You can see that 2023-02-27 (a copy of which is seen below) is displaying in the dataview query provided.

# 2023-02-27
# 📅 Daily Tasks

- [x] Journal
- [x] Brush teeth
- [x] 5,000 steps (check Paseo)

But, for example, 2023-02-26 (a copy of which is seen below) is not displaying as it should due to the extra text added on by the ‘Tasks’ plugin.

# 2023-02-26
# 📅 Daily Tasks

- [x] Journal ✅ 2023-02-27
- [x] Brush teeth ✅ 2023-02-26
- [x] 5,000 steps (check Paseo) ✅ 2023-02-26

Is it possible to adapt your query to work with the extra text that the ‘Tasks’ plugin adds? I see what you mean regarding the fragility of a text matching system, how would a tag based system look in comparison?

You can switch the check from an equality check to a “starts with” check, so try the following:

```dataview
TABLE
  journal.status as "Journal", 
  teeth.status as "Teeth", 
  steps.status as "Steps",
  tJournal, tTeeth, tSteps
FROM "To-Do/Daily To-Dos"
FLATTEN filter(file.tasks, (t) => startswith(t.text, "Journal")) as journal
FLATTEN filter(file.tasks, (t) => startswith(t.text, "Brush teeth")) as teeth
FLATTEN filter(file.tasks, (t) => startswith(t.text, "5,000 steps (check Paseo)")) as steps
FLATTEN choice(journal.status = "x", "Written", " ") as tJournal
FLATTEN choice(teeth.status = "x", "Brushed", " ") as tTeeth
FLATTEN choice(steps.status = "x", "Walked", "Null (or failed)") as tSteps

SORT file.name
```
1 Like

This is pretty much bang on what I was looking, thank you again! Do you have a ko-fi or somewhere that I can small a small donation as thanks?

Also, do you have any resources that you would recommend for learning to write these queries myself?

It’s not needed with a donation, but there is a simple link in my profile.

Regarding where to learn, I’ve not used that many resources besides the documentation of the various plugins and this forum, and testing. Loads of testing. Of course it does help that I’m a programmer by trade, so I kind of now what to look for and how to do various stuff with a coding background.

Another resource which possibly could spark a lot of ideas (but it’s a rather large thingy), is the dataview example vault: Dataview Example Vault

In there is loads of stuff showing how to do loads of stuff. I’ve not used that much, and should possibly take some time study it, as I’m sure I could learn a lot. But I’m sure it could provide pointers, ideas and resources for how to do must stuff, if you just can locate it.

Finally, asking questions in the forum where you show that you’ve done a little research (and not just saying I’ve searched and couldn’t find anything), and providing good examples on what you’re trying to achieve and how far you’ve gotten, is a good way to get people look at your request and be helpful about it. (Even a well documented faulty attempt, is better than just asking for someone else to do it on your behalf, in my book at least)

1 Like

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