Query to link traits to a person

What I’m trying to do

In my daily notes (/001 Dailies) I might write something like:

  • [[Person A]]:: Strength +1
  • [[Person B]]:: Intelligence +1

And then, on each of the Person’s file, I want to add a dataview that shows me something like:

Trait Value
Strength 7
Intelligence 3
Agility 0

Things I have tried

I’ve tried fumbling with dataview, but I don’t understand it :frowning:

1 Like

If you want something similar to the screenshot below, please see the files attached for the data and code.

001 Dailies.zip (2.7 KB)

1 Like

A slight variation of what @anon63144152 wrote, and perhaps closer to your initial markup would be to add something like the following in your daily notes:

- [[Person A]] [strength:: +1]
- [[Person B]] [intelligence:: +1]

However, whilst that would look a little nicer, it wouldn’t be as easy to produce a table of all the traits. That is, producing rows for each trait. This syntax would to some extent allow for traits as columns.

I had some issues building this query, as it turned out to be a bit of a nightmare to group/flatten/sum the various thingies… :frowning:

If needed, I could continue trying, but not tonight…

Alternative markup for Eightnings solution

Eightning used [trait:: strength] which keeps showing the field name. And alternative but still using the same field, would be to do (trait:: strength). Using this markup we could get something like (I’ve also dropped the person field:

- [[Winter]] (trait:: strength) (offset:: +1)
- [[Winter]] (trait:: intelligence) (offset:: -1)
- [[Autumn]] (trait:: strength) (offset:: -4)
- [[Winter]] (trait:: strength) (offset:: +4)
- [[Winter]] (trait:: strength) (offset:: -2)
- [[Autumn]] (trait:: strength) (offset:: -8)
- [[Winter]] (trait:: intelligence) (offset:: -1)

which in my setup shows as:
image

This could be styled according to your own desire. I’m using similar markup where I add some symbols related to field names, and so on.

And the queries if I’m assuming you want to collate the trait offsets from the various files would look something like the following:

### List all trait changes (for this file)
```dataview
TABLE item.trait, item.offset
FLATTEN file.lists as item
WHERE econtains(item.outlinks, [[]]) AND item.trait AND item.offset
SORT item.trait
```

### Sum trait offsets
```dataview
TABLE sum(number(rows.item.offset)) as Offset
FLATTEN file.lists as item
WHERE econtains(item.outlinks, [[]]) AND item.trait AND item.offset
GROUP by item.trait as Trait
SORT item.trait
```


### Current trait value
```dataview
TABLE this[key] + sum(number(rows.item.offset)) as Value
FLATTEN file.lists as item
WHERE econtains(item.outlinks, [[]]) AND item.trait AND item.offset
GROUP by item.trait as Trait
SORT item.trait
```

In addition to some settings like the list item, I’ve here also included the following frontmatter for “Winter”:

---
intelligence: 40
strength: 100
---

Which then gives me the following output:


I’m imagining this to be used for some variant over character building, where the person has some base values, and then these values changes over time. Maybe related to training, exercises, challenges, and so on…

1 Like

A joy to read.

Without a key for Person, is it possible to extract data about Autumn and Winter in other queries, such as making a list from my daily notes of the days I had lunch with them? Or better to keep the key for future use in case the need crops up?

- [Person:: [[Spring]]] [Trait::Intelligence] [Value:: 11]  
- [Person:: [[Summer]]] [Trait::Treachery]  [Value:: 3] 
- [Person:: [[Spring]]] [Trait::Kindness]  [Value:: 8] 
- [Person:: [[Summer]]] [Trait::Kindness]  [Value:: 6] 
- [Person:: [[Spring]]] [Trait::Fear]  [Value:: 2] 
- [Person:: [[Spring]]] [Trait::Laughter]  [Value:: 7] 
- [Person:: [[Summer]]] [Trait::Intelligence]  [Value:: 9] 
- [Person:: [[Summer]]] [Trait::Fear]  [Value:: 1] 
- [[Winter]] (trait:: strength) (Value:: +1)
- [[Winter]] (trait:: intelligence) (Value:: -1)
- [[Autumn]] (trait:: strength) (Value:: -4)
- [[Winter]] (trait:: strength) (Value:: +4)
- [[Winter]] (trait:: strength) (Value:: -2)
- [[Autumn]] (trait:: strength) (Value:: -8)
- [[Winter]] (trait:: intelligence) (Value:: -1)
#traits

```dataview
TABLE WITHOUT ID
Person, Trait, Value
From #traits 
LIMIT 20
```

Using a field like you did with Person you got an anchor which can be used anywhere within the field. Using just a link, is a looser anchor, which especially in combination with other links is depending on the context.

If you’re consistent in making the first link be something special, you can use other links for other purposes. If you know with yourself that you might fumble that up by changing wording/placing of links, you’re better of using a field definition to have a better (and named) anchor to your person.

Within the body of the text, I don’t think there is any change to how the link behaves whether it’s within an inline field definition or just in the text. (There is of course a difference related to how you’d refer to it from a query, aka file.person or file.outlinks[0] or similar)

1 Like

Thanks for that. I think I need the anchor as my workflows and my brain are both so unruly, but certainly good to see other ideas that push the boundaries of my limitations.

God helg.

This is so amazing! thank you so much! Obsidian sure is versatile.

How did you make it so the inline metadata shows up styled like in your picture? In mine, they don’t style up, they stay as flat text.

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