Dataview -> extract only matched Line from Page

What I’m trying to do

I have a daily note where I note down different topics I’m working on. All of those have an inline field with (Topic::XXX) written in the line. Throughout the day multiple different topics pop up and I write down all of those in on different lines (not tasks, not bullet lists), but all of them have the (Topic::XXX) field, where XXX is the corresponding topic.

I want to add some of them to their own page for a weekly meeting I have with my boss and note those topics/memos.

Things I have tried

So I tried to add a hashtag in front of the line, I also tried it with linking to another page. I also added some other inline fields (like the meeting-date, details about the topic, …)

Then I tried querying it all via:

```dataview
TABLE WITHOUT ID Datum, Thema, Detail, file.link AS Notiz
FROM #myhashtag

In the results I get the following:

So if there are multiple values for a Thema but I only want to see the one which actually has the filter-criteria in front of it. How do I get that?

It’s difficult to understand your goal and the previous knowledge you have about dataview.

To start, dataview works with data (things recognized as metadata), not with the full content of your notes.

In data side, things have a hierarchical structure and defined relations. And this is very important. For example, you said:

  • add a tag to the line is irrelevant if the line isn’t a task or a list. in the case, the tag is related with the page, not with the line, the block, …
  • same thing to inline fields.

So, the first thing to understand is the metadata structure. In a specific note you can add this inline query (you need to enable the js queries in settings > dataview) and see the metadata structure in that note:

`$=dv.span(dv.current())`

The second point is related with you direct question:

Well, the answer depends. We don’t know the relation between Thema, Detail and Notiz… We can explore a way via flatten command or directly with a filter in the Thema column. But all depends on the relation with the other fields.

The core of dataview is in the metadata structure. We can create relations based on the knowledge of that structure. Do the content without that knowledge and apply a posteriori the abilities of dataview isn’t the best method.

In addition to the excellent answer from @mnvwvnm, I would like to target one of your prerequisite of it not being a task or bullet list. As indicated in the other answer, it complicates (or makes almost impossible) to get the various data out of the note which you say you want to take out of it.

So the question then becomes, why don’t you want it to be a task or a bullet list? One answer could be the visuals, of it, but then there also exist some rather neat alternatives, examplified in the Minimal theme, with task decorations, see Checklists - Minimal Documentation .

image

The image above is constructed, but it shows some alternatives, where all the lines with the icons are tasks with text, which are easily extracted with Dataview. The last two shows two which are tagged with topics as inline fields, also easily extracted. The two first has additional text in a separate paragraph, to indicate that you could write fuller text related to the “header” task. (Those paragraphs are not so easily extracted again… )

Finally, if you’d like to further enhance the visual appearance, it’s no problem to use CSS to change style and placements of these tasks. And it’s very easy to add custom icons, so if you’ve got a limited set of topics, you could easily create custom icons for those topics. I’ve not styled the inline fields myself, but I reckon you could even style those if you’d like to.

All in all, what I’m really trying to bring across here, is that you’ve got a lot more, and easier options, if you use decorated tasks for the notes on what you’re working on. Those tasks, will be a magnitude easier to extract into summaries at the end of the week/work period, than anything based upon lines/paragraph.

Each of these tasks will also have the added benefit of being the target of the tags/inline fields they contain, which can’t be said for tags/inline fields in the body text/headers of your notes.

Hello to both of you and thank you so much for your help so far.

I realize I may have made a mistake when setting up my workflow. Honestly I didn’t think about it too much and was just writing down stuff and adding some inline fields where possible and now I realize it doesn’t really make sense and I can’t extract it the way I want to.

I am actually using tasks and use those as a to do list for stuff I need to get down for work. My worried were: if I now add tasks anywhere else I would complicate things and make a mess with my task plugin overview pages or would have to tag the tasks etc. but I get your point.

So if I understand both of you correctly the easier option would be to add tasks wherever I think I will need to „extract“ those at some point as they are their own „thing“?

How do bullet point lists compare to those and is there anything I should consider after when using dataview with tasks? I’d like to be able to generate a table at some point, as for example the one I mentioned in my initial post where I would have 3-4 fields per task/bullet point/… and generate a table from there. Does the DQL work the same?

I realize those may seem like stupid questions or questions all over the place, I’m still pretty new to all things obsidian but love it so far and would like to use it even more.

A big big thank you to both of you again.

1 Like

After the great @holroy focus in tasks, I use lists (same for tasks) as examples of a sub-structure data. Saying it another way: a way to explore metadata in a sub-structure nested in main page metadata structure.


Example note


#work 

## work topics

- (topic:: meeting) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet eu nibh sed pharetra. (date:: 2022-11-05)
- Aenean eu magna vel nulla vulputate faucibus.
- Donec at interdum mi, a scelerisque lorem. (topic:: client) Ut laoreet turpis enim, nec elementum augue commodo vitae.
- (topic:: meeting) Suspendisse orci augue, ullamcorper eu enim id, sollicitudin tristique risus (date:: 2022-11-07)


Exploring queries

Now, as first query, explore the field topic as a field at level page:

TABLE topic, file.lists.text
FROM #work 
WHERE contains(topic, "meeting")

As you can see, topic is a key at page level. At this level, filter the topic means filter the page where the field exists.

Now, let’s explore the field topic as also a metadata nested in the file.lists level. For that we need to flatten the array file.lists and add the name Lists to the produced objects.
After that we can explore metadata inside each object.

Fo example, create a table with the text of lists only with the topic meeting (observe that now we add the prefix Lists - the name used before - to each inline field inside the list text):

TABLE Lists.text
FROM #work 
WHERE file.lists
FLATTEN file.lists AS Lists
WHERE Lists.topic = "meeting"

Or filter the previous results with a specific date:

TABLE Lists.text
FROM #work 
WHERE file.lists
FLATTEN file.lists AS Lists
WHERE Lists.topic = "meeting"
WHERE Lists.date = date("2022-11-07")

Results

4 Likes

I’ve not used the Tasks plugin, so I don’t really know the ins and out of it. But I just installed it, just to see the basic of it, and it seems like in the default setup it’ll take all the decorated tasks, and consider them as completed. (I’m now going to uninstall that plugin, as I’m kind of enjoying my own setup related to task handling. :slight_smile: )

In addition, it seems to be possible to mark the “actual” tasks with something like #task (or whatever you feel like), and then remove this tag using the global filter options. Then I reckon the decorated tasks won’t show at all as completed tasks.

Lastly, both task and lists allow for tags and fields to connect to them, so the queries would look similar (if not identical in some cases). The main thing which we’re trying to get across, is that you’re much better of using either lists or tasks instead of just the body text.

1 Like

Hello again,

thank you again, for all the help and trouble you went through, that was very enlightning to me and does make a lot of sense. I’ll try to setup my notes differently and then use a version of the query you showed me.

Thanks again :slight_smile:

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