I’m currently adding some locations based properties to my notes on companies & people since that makes sense for the job I do. Using folder notes, I have created a file tree for locations like Europe>Western Europe>Belgium>Leuven. Where each folder also has a MOC folder note.
Now I have a location property where I want to link notes (can be companies, people, events …) to a certain location (e.g. Bpost is a Belgian company so I link Belgium in the Location prop of Bpost).
Now I want to have a dataview in my location notes with all companies that I have a note about in that region. This on all levels of my location hierarchy (e.g. Europe, Western Europe, Belgium, Leuven).
Things I have tried
A very basic implementation I had was just using this basic dataview query in my location pages:
LIST
FROM #Company and [[]]
Main issue here is that for this to work as expected (e.g. Bpost showing up on all levels → Belgium, Western Europe, Europe), I would need to add a link manually in the Location field to all levels of the hierarchy. Is there a way through dataview queries to only add the lowest location level in the hierarchy (e.g. City or Country) and for it to still be retrievable through dataview queries? Or is there a plugin that can auto add property links based on some rules?
You might be able to use a given link to stay the chain, and then use split(link.file.folder, "/") to do some magic when building new links.
But it also depends on how and where you want to link what files. In some cases you could possible use startswith() clause to match the current query.
In other words please give some examples on typical notes, and what you want to query for fun which files. I’m just not fully understanding which use case(s) you’re aiming for.
Each folder has a folder note (as in each folder has a MOC).
What I’m looking for (company use-case)
A company file like “Bpost” has a property “Location” that can link to a location MOC (e.g. Leuven, Belgium, Europe or America etc).
I want that each Location MOC has a dataview query of all companies that are located in that area (e.g. if Bpost is located in Leuven, it should show-up in Leuven, Belgium and Europe).
Each Location (City, Country, Continent) has a property linked to it’s parent.
My main issue is that the “easy way” to do this needs me to link each hierarchical level to the company note (e.g. in the location property of “Bpost”, I need to link Leuven, Belgium & Europe).
My question is if there is a way as such where I would only need to link “Leuven” and because of how the hierarchy is build-up, I can also query on it in the Europe MOC.
Hmm it seems to be a step in the right direction but not fully. It seems to include all files tagged with #Company (in the EU MOC is also has the ones from the States)
The files with #Company are not in the locations folder but in a separate one.
Now I used your suggested Dataview query in the Europe folder note and it just returns me all files with #Company, I only want the ones that have a location linked that is in Europe or Europe itself
To use the alphanumeric identifier, for example, you have a parent note with the ID 100 and children like 101.1 and 101.2, these notes can have child notes like 101.1a1 and 101.2b1. Be careful with this system because if you put a “10” or “aa” you might break the order because numbers take precedence over letters, so the note 10.10a would be above the note 10.9a even though the note was made first. This doesn’t happen in Obsidian.
```dataview
TABLE
FROM #Company
WHERE contains(split(string(location.file.folder), "/"), split(this.file.folder, "/")[length(split(this.file.folder, "/")) - 1])
```
When you put that in an MOC note, it looks in the #Company note’s Location value’s paths for the MOC’s immediate folder. So every lower level location should show up.
I saw your Location is a list type, so the query handles company’s with multiple locations.
Note that this is for your MOC notes, not for the city notes themselves. Pasting this into “Brussels.md”, for example, would list all companies in Belgium, not just company’s linked to Brussels.