Dataview List with "OR"

Things I have tried

The blow and other code variations. Doesn’t Work. Not sure of syntax. All others broke dataview.

What I’m trying to do

Generate a list with YAML that is either “Grant” or “Competition”

TABLE WITHOUT ID link(file.link, Name) as "Name", Type, Note
FROM #note/type/company
WHERE contains(Type, "Competition" OR "Grant")
SORT Name DESC

Is Type a single value or an array? It possible seems to be an array, but we can do this another way if it’s a single value.

With it being an array, you either need to repeat the condition, or do some array manipulations with any() and/or filter().

The easiest is possibly to do the following:

WHERE contains(Type, "Competition")
   OR contains(Type, "Grant")
2 Likes

Thanks! That worked!

Copuple more questions sorry:

  • I’m getting my template in the list as well. How can I exclude the Templates folder?
  • The Name sort doesn’t seem to be in alphabetical order either with ascending or descending. Some of the names are two words, but I assume it should sort by first word??

Cheers,

R

You can exclude the templates folder in the FROM part, or in the WHERE part.

If you got a FROM part, I would add the following to that line:

AND -"Your/template/folder"

Regarding the sorting, you’re sorting on the link, and not the actual name. So try using something like file.name in the sort statement, to ensure you’re sorting on the name, and not the link.

Must be doing something wrong: Here is my code now

TABLE WITHOUT ID link(file.link, Name) as "Name", Type, Note
FROM #note/type/company AND "Second Brain - 2023/Templates"
WHERE contains(Type, "Grant") 
OR contains(Type, "Competition")
SORT file.name DESC

sorting seems to work now, but still looking my templates folder. is it because my database is multiple words? I tried also w/o “Second Brain”. Also tried “!” instead of “-”

Is your templates folder equal to “Second Brain - Templates/Folder”?!

Or is that two folders? In that case you need "Second Brain" AND -"Templates/Folder"

In case you want to torment yourself a little, you can try any of the various scripts, which requires the Type to be an array.

Various filter() and map() queries

Throw the following in a file:

## List all types

```dataview
LIST join(type, ", ")
FROM "ForumStuff/f51152"
```

## Table query with map & filter
```dataview
TABLE Type,
  map(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as M,
  filter(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as F
FROM "ForumStuff/f51152"
```


### Limited by filter
```dataview
TABLE Type,
  map(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as M,
  filter(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as F
FROM "ForumStuff/f51152"
WHERE filter(Type, (t) => contains(list("['Grant', 'Competition']"), t))
```

### Limited by map
```dataview
TABLE Type,
  map(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as M,
  filter(Type, (t) => contains(list("['Grant', 'Competition']"), t)) as F
FROM "ForumStuff/f51152"
WHERE any(map(Type, (t) => contains(list("['Grant', 'Competition']"), t)))
```

## Finally the same in LIST

```dataview
LIST
FROM "ForumStuff/f51152"
WHERE filter(Type, (t) => contains(list("['Grant', 'Competition']"), t))
```

And adjust the FROM to match your case.

This could then produce output like the following:

Notice the multitude and variants of list output within the table for the various files, and hopefully you could get some use out of how to combine various filter(), map() and any() function in a query.

Second Brain is the name of my database and templates is the next level down.

This looks great, but a bit over my head. :slight_smile: But I do like the idea of having more control over results. I dont want to over complicate, but I’m trying to think ahead so I can set up the YAML correctly and not have to go back in to all the old notes when I think of something later.

One thing I might want to do is generate a list of grants, not by name, but by year applied. I think that should just be a sort, but what happens if I apply for the same grant in multiple years? How does one set up the YAML and how does one query/how do the results display/sort, but the 1st or 2nd year, etc.

That doesn’t really answer my question. Do you have a folder within your vault called “Second Brain - 2023/Templates”, or not? Or is possibly your folder “2023/Templates”?

Without knowing the exact names of your folder, it’s hard to help.

1 Like

I fixed it… I just had to remove “Second Brain” and write only Templates… there is no folder called “Second Brain”… Templates is a level one folder.

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