How to add and access repeated metadata in a file?

I am starting to use Obsidian and I am trying to understand how to use metadata in a file, and then access it through dataviewjs.

I would be glad for pointers for how to address the question below, or whether it is possible at all. I will be digging deeper afterward, I just need pointers (this is to explain why the "what have you done so far is empty :))

It would be awesome if i could add TODO elements within a note and then access them on a separate page (gathered from all pages). Something along the lines of

(in file meeting with

There were plenty of people, the budget is 100B€
::todo make sure the oven is off
Decision was to go ahead and buy 100 pokemons

::todo is an example of “metadata indicator”, I believe this is the way it is added inline.

This construction could happen several times in a file, and then in several files.

Ultimately, the aggregated information (for that single example) would be something like

make sure the even is off → 2022-07-04 → [[meeting with John]]
another todo somewhere else → 2022-03-27 → [[wazaa]]

Is this at all possible? - or in other words: can metadata within a file be extracted when it is repeated? (such as several todos per file)

Hi Wpq,
You almost have the dataview inline field syntax: it is field name, then ::, then value, so in your case todo:: make sure the oven is off.

You can repeat the same field name in a file, the values will be combined together into a list. Tags are another example of this. You will probably want to take a look at the dataview command FLATTEN for how to undo a level of list nesting when querying.
Note that while FLATTEN works well for a single repeated field, if you have multiple correlated fields that you are repeating, that gets much more complicated with dataview.

Dataview has additional options for tasks specifically, such as a dedicated TASK query that will work on lines that start with list + checkbox. (e.g. empty checkbox is - [ ]. Take a look at the “Data Annotation” page of the dataview documentation for some of the information that dataview can provide on tasks automatically.


Thank you very much @scholarInTraining .

For reference, the simple code I tested is

let pages = dv.pages().where(p => p.todo)


The first one uses my idea of a todo:: and is a bad idea, compared to your suggestion to use a task (last line of code). A task is interactive and can be filtered as well.

The result (for the last line) is


I wonder if there is a way to customize this display (say, list tasks by week)?

I use AutoHotkey, and type tsk<space> to generate a new task:

::tsk::- [ ] 

Absolutely there is!

  1. Get rid of the default grouping by filename: there is an optional second argument to dv.taskList(); set it to false to stop the grouping by filename. e.g. dv.taskList(pages.file.tasks, false). Now you should have no grouping.

  2. Take a look at the GROUP BY command in the querying documentation to write your own grouping (groupBy in dataviewjs). dv.taskList(data, false) will happily accept grouped data; you do not have to write your own loop through the groups the way you do for tables and lists in dataviewjs. For a simple example, you could group by whether the task is completed: dv.taskList(pages.file.tasks.groupBy(t => t.completed)).

  3. “list tasks by week” I am not sure exactly what you mean with “by week”. Are all your tasks coming from files whose names are dates? Or are you thinking about putting a due date or a created date on the task itself? (Check the “Data Annotation” page in the dataview documentation!)

Ah la la, so much useful information - THANK YOU @scholarInTraining.

I will be using dataviewjs because I feel more comfortable in JS. I understood all of your comments (for the last one you gave a complete example in point 2.).

1 Like

Makes sense, but the dataviewjs documentation assumes you have read the non-JS documentation, especially for the querying operators, so I highly recommend doing that!

1 Like

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