Search combined dataview fields and display them in one column?

I’m currently using Obsidian for my genealogy research. I’m trying to track multiple people and their information that’s mentioned in multiple documents and I’d like to use dataview to view some of the information but I don’t know if it’s possible to do it.

If I have a document that mentions several people, I’ll tag each person and the relevant data for each person. Some of the fields could be blank, and the number of people mentioned won’t always be the same from one note to the next. For example the fields in one document note could look like this:

person1_name: [[Smith, John]]
person1_birthplace: [[Springfield, Illinois]]
person2_name: [[Doe, Jane]]
person2_birthplace: [[Greendale, Colorado]]
person2_birthdate: 2022-07-21

I’d like to search for any of this data and have it displayed along with the person it connects to. So if I query dataview to search both person1_birthplace and person2_birthplace for “Greendale” in my documents folder, I’d like it to display in a table every person attached to that location and their other data from the document, whether they’re under person1 or person2. In this case, it would only display all the information of [[Doe, Jane]] from this note, nothing from anyone else in the note.

Is there any way I can do this with dataview?

1 Like

After a lot of trial and error, I’ve got it (mostly) working. The data has to be a task, the search is case sensitive, it won’t search inside an internal note’s real title if using an alias, and sometimes it just doesn’t work even though the code hasn’t been touched. Aside from that, I think I’m ok with what I’ve cobbled together.

I’ve used mnvwvnm’s code from this thread and changed it to suit my needs.

This is the final table:


The “Testing Source” in the table is from the note’s yaml. Since tasks also get all the fields from the note they’re located in, I put all the source document’s values in the document note as yaml so every person’s data chunk will inherit them.

Below are the different data formats that will show up on the table correctly. For the last 2 data chunks, those aren’t new lines but the shift+enter lines (or whatever’s the actual term for those).

 - [ ] (person::[[Smith, John]])(person_birthplace::[[Greendale, Colorado]])(person_birthdate::2022-07-21)(person_name::Smith, John O)
 - [ ] (person::[[Smith, John]])
	(person_birthplace::[[Greendale, Colorado]])
	(person_name::Smith, John O)
 - [ ] [person::Smith, John]
	[person_name::Smith, John O]
	[person_birthplace::Greendale, Colorado]

This is the dataview code:

TABLE WITHOUT ID Tasks.person AS "Person", Tasks.person_name AS "Name", Tasks.person_birthdate AS "BDate", Tasks.person_birthplace AS "BPlace", source AS "Source", AS "File"
FROM "z_Test"
WHERE file.tasks
FLATTEN file.tasks AS Tasks
WHERE contains(Tasks.person_name, "Smith")

Note that this has the limitation that if you’re using an alias for an internal link, it will not see the actual note title. So if you have a link like this: [Greendale, Evergreen County, Colorado|Greendale, Colorado] then contains() will not see “Evergreen” or “County” if you try to search for those terms. It’s also case sensitive, so searching for “green” in the birthplace won’t pick up anything.

This isn’t perfect, I’d like it to work consistently and for the cells to not be wrapped, but it will work while I think about how I can fix it.

If anyone has any tips or suggestions on how to improve this, please let me know.

1 Like

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