How to sum dataview values of a certain task field in different files

Let’s say I have in different daily notes some tasks like:

2023-01-23 [title of my daily note]

- [ ] Teaching Descartes [startTime:: 09:00]  [endTime:: 11:00]

and another file

2023-01-26 [file’s title]

- [  ] Teaching Kant [startTime:: 12:00]  [endTime:: 14:00]

In the weekly review, I would like to sum the time I spent this week in my area “Teaching”.

I would like to create a chart with these values and values of another areas (e.g. “Research”, “Administration”). Perhaps developing on something like this Using Dataview with Charts in Obsidian – But this is perhaps for another help thread.

Have you built any queries which gives you part of the data you’re wanting to see? What have you tried?

I see one possible “issue” with your format, and that is that you don’t seem to have a way to easily pickout the entries which are related to teaching, unless you can rely on those being the only ones starting with the text of “Teaching”. Similar would also apply to those other areas like “Research” and “Administration”.

Regarding the name of your files, you’ll need to tinker a bit with the file name in order to get at the date it represent. This would potentially require some usage of the startswith function, or substring function, which could lead to sub-optimal performance.

If you’re using templates to create your files, I would strongly consider to add a date field to the frontmatter to have easy access to the date of the current file.

I would also suggest doing something like the following to help pick out the topics of your items more easily:

- [ ] (topic:: Research) Kant before teaching it...
- [ ] (topic:: Teaching) Kant [startTime:: 12:00] [endTime:: 14:00]

Hope this helps a little, but it would nice to see what you’ve tried, and which queries you’ve come up with so far, and also the expected output (even though/if you can’t get that with your current queries)

Thanks for your reply. Yes I see what you mean, I think I have to make things a bit different in order to have the possibility to achieve what I’m striving for.

As soon as I come up with a better idea I’ll edit my original post. Hopefully, other folks will then step in with a solution.

let pages=dv.pages(‘“path”’).file.tasks.where(t => t.text.includes(“Teaching”))

Sorry, I’ve zero knowledge of JS. Could you please expand on that?

I tried this one:

let pages=dv.pages(‘“path”’).file.tasks.where(t => t.text.includes(“Teaching”))

but get an evaluation error.

Step 1: Find the file containing the teaching task. The script I provide can do this
Step 2: According to the file meta information found, count the time you need, which I don’t know
The ‘path’ of the script means that you need to search the teaching folder path and need to modify it

1 Like

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