Ordering Dataview Table based on number of results in a column

Things I have tried

What I’m trying to do

I am trying to create a table which references personality traits in order to figure out which personality traits a particular character wouldn’t get along with. I have inline fields with TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT:: in every note. I link other notes about personality traits into that. For example, for the personality trait “Addictive” I have

TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT:: [[Innocent]], [[needy]], [[persistent]], [[proper]], [[pushy]], [[rebellious]], [[responsible]], [[tactless]], [[volatile]]

I then wrote a dataveiw table.

TABLE TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT
from outgoing([[NewName]])
Flatten TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT
Sort TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT Asc

This tables all conflicting traits associated with the traits listed on the particular page I’m working on. The idea is to build a template which can quickly show the types of personality traits a character would not get along with so I can look for conflict between characters.

What I’d like to do is list the conflicting personality traits based on the number of times they come up on the list. For example, if I list [[Addictive]] [[Childish]] I get a table which shows two hits for [[responsible]] and two hits for [[proper]]. This means they would not get along with someone who was responsible and proper. I want that data to come to the top since very other trait only comes up once on the list. How can I get responsible and proper to come to the top of the list based on the fact that they are in the list twice and everything else is only listed once?

I for the life of me can not figure it out. Thank you in advance.

Sorry but for me it’s very confused to understand what you want. A list? A Table?
Some observations.

  1. A simple suggestion: simplify your key fields. Names as “TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT” are not pratical to write queries. If you use inline fields (not yaml front matter fields) you can anticipate the field with a heading or bold, and after add a simple key like this:
## Traits in supporting characters that may cause conflict

Conflits:: [[Innocent]], [[needy]], [[persistent]], [[proper]]

  1. For a better understanding of the desired solution, simulate a (false) list or table to communicate the kind of result you want to achieve.

  2. Test this:

```dataview
TABLE length(rows.file.link) AS "Number of times"
FROM outgoing([[NewName]])
FLATTEN TRAITS_IN_SUPPORTING_CHARACTERS_THAT_MAY_CAUSE_CONFLICT AS Conflits
GROUP BY Conflits
SORT length(rows.file.link) DESC
```
1 Like

Brilliant! Thank you! Now I’m going to spend the next hour picking apart your solution so I can learn how to better understand this programming protocol.

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