Dataview: How do I make a table that shows only yaml properties that are TRUE?

What I’m trying to do

I’ve got a note with lots of yaml properties. A section of them are checkbox types, so end up with values of TRUE or FALSE.

I would like to make a table in the body of the note that compares the notes by which properties they have that are TRUE.

Example

I’ve got a note for each planet in my ttrpg worldbuilding. Each has a set of properties that indicate whether they have a specific resource (hasMinerals: :white_check_mark:; hasLabor: ( ); hasExoticTech: :white_check_mark: and so on).

I want a table that lists out the planets, showing the properties that are only TRUE for each planet (key thing is that it lists out the names of the properties and not the values of TRUE).

Things I have tried

I have been doing a lot of trial and error using “filter” and “extract” commands, but they either give me the values of TRUE and not the matching property names, or they show all the info but without filtering out the FALSE ones.

Thoughts? Thanks!

Hi @ahmaddialdin ,
Let’s assume we have notes named planet1, planet2, planet3. Each of these notes contains the following properties in the frontmatter section:

---
hasMinerals: 
hasLabor: 
hasExoticTech:
---

Planets in notes have the following settings:
Planet1
hasMinerals: true
hasLabor:
hasExoticTech: true

Planet2
hasMinerals:
hasLabor: true
hasExoticTech:

Planet3
hasMinerals: true
hasLabor: true
hasExoticTech:

Here’s an example of displaying planets that have minerals (property hasMinerals):

TABLE WITHOUT ID
file.link as "Note",
FM.hasMinerals as "hasMinerals"
FROM "Path/To/Your/Planets"
FLATTEN file.frontmatter as FM
WHERE FM.hasMinerals

The output will look like this:

I hope this helps! Have a great day.

1 Like

Thanks so much for the quick reply @sysbreaker.

So how would i extrapolate that for all the properties? Using your example, I want it to show me that planet1 has minerals and exotic tech, planet 2 has labor, and 3 has labor and minerals.
I’m getting lost in how to have it check against all properties and show the different true ones for each.

As an example of what I was trying to achieve, here’s the closest to what I’ve been able to pull off.

By doing this:

TABLE WITHOUT ID
file.link as “Planet”,
filter([hasSystem, hasLocation, hasHabitability, hasMinerals, hasExoticFloraFauna, hasLabor, hasExoticTech, hasRuins], (x) => x=true) as “Filter”
FROM (“path to folder”)

I can make this happen:

It’s showing me all the TRUE values (knowing that they’re different for each planet… e.g. Mihwar hasMinerals, but Xenia hasLabor), but it’s not showing the names of the properties themselves.

Here are some untested code showing the gist of how I would approach this:

```dataview 
TABLE WITHOUT ID
  file.link as “Planet”,
  join(list(
    choice(hasSystem, "System", ""),
    choice(hasHabitability, "Habitat", ""),
    choice(hasLocation, "Location", ""),
    choice(hasExoticTech, "Exotic Tech", "")
    ), ", ") as Resources
FROM (“*path to folder*”)
```

This way you can divide and conquer the presentation of the various resources any way you like. Maybe you would like resources related to survival in one last, and more of a social nature in another, or similar. It also allows for different wording of the field vs presentation.

1 Like

Oooo yes, didn’t think of the join function at all. This definitely gets the output I was looking for. Thanks @holroy!

image

It does mean some extra commas to deal with, but overall it works great!
And has the added benefit of customization as you mentioned in your comment.

Try using 0 or maybe nul instead of "", and/or combine it with filter() (or maybe map). It should be doable to loose the extra commas…

I’m on mobile so it’s a little hard for me to test the various options, but aim for the stars without any extra commas.

Yup, my first thought was adding a filter around the “join” to see how to filter out the commas. I’ll play around with that.

Thanks @holroy . I learn something new from your answers every time. :brain::+1:

@ahmaddialdin, to get rid off blank fields in output table, replace this line:
), ", ") as Resources with this ), " ") as Resources :wink:

Thanks @sysbreaker. Yup, it gets rid of the blank fields, but leaves the entries all as one continuous string:

Shooting for the stars: just trying to figure out how to delimit between them with commas or so on.

Haven’t found the right combo of nulls and nonnull or map or filter, etc. yet… half the fun is the trial and error, but need to look at it some more.

Try the following:

```dataview 
TABLE WITHOUT ID
  file.link as "Planet",
  join(nonnull(list(
    choice(hasSystem, "System", null),
    choice(hasHabitability, "Habitat", null),
    choice(hasLocation, "Location", null),
    choice(hasExoticTech, "Exotic Tech", null)
    )), ", ") as Resources
FROM "some/folder"
```

That did it!

Your timing is uncanny… I had just finished testing out an array version of that (basically sans join function):

TABLE WITHOUT ID
file.link as Planet,
  nonnull(list(
    choice(hasSystem, "System", null),
    choice(hasLocation, "Location", null),
    choice(hasExoticTech, "Exotic Tech", null),
    choice(hasRuins, "Ruins", null)   
    )) as Resources
FROM *path to folder*

So I love having both options working… thanks to both of you for the quick and awesome problem-solving session today. Feels great that I learned how to manipulate dataview from what you guys showed me. Totally appreciate it!

2 Likes

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