Dataview Question: Query by Key & Value?

Things I have tried

research

What I’m trying to do

new to dataview, but very cool plugin.
I’m getting how I can create lists from arbitrary keys, but can i create a query from only specific the values? e.g. Let’s say I have

---
Type: Blog 
---

and in another note

---
Type: Article
---

Can I return only Type = Blog from a certain folder? or can I only make a table based on Type, which will then return a list of all blog and article files in a list?

Or is this better suited to a tag #type/blog and #type/article and do a query that way?
If so, is this better to do via YAML and dataview or simply have a tag in the note and use the standard Obsidian searching.

What are the pros and cons of each of these 3 methods and how would you set each up?

thanks so much!

List 
From "" 
Where type = "blog" 

Or alternatively, to select notes that have a “type” but are not blog.

dataview 
List 
From "" 
Where type != "blog" and type != null

Of course, you can experiment with both types and see what works for you over time.

For your example, I would choose the #tag/subtag option, because you can still use dataview, but having it as a tag is probably going to bring more benefits and be easier to use.

dataview 
List 
From #type/blog 
2 Likes

this is great info. Thanks!

1 Like

Starting to implement this and not wanting to repeat info. as an additional tag which is already a key… how might one write a dataview query such that I could return every newsletter (designated w/ a tag ) that is by a specific author (designated w/ a key/value)? E.g.

Author: “XXX”
Tag:

  • " #note/source/blog-newsletter"

or, if the author only has newsletters, then could simply write something like you suggested:

List 
From "" 
Where Author = "XXX 

FROM #SpecificTag
Where author = “xxx”

Should do it I think.

1 Like

very cool! thx!

on second though, that didn’t work, either got an error or finally with this version, zero results, though there should be.

LIST FROM #note/source/blog-newsletter
Where Author = "XXX
SORT file.name DESC

scratch that. I did get it to work by removing the spaces around the equals sign for author.
thanks!

Is there way, when returning tags, to return only a specific set from nested tags? e.g.
If I have in my YAML #cat/philosopher, #note/permanent-note, and #topic/religion, #topic/logic, topic/mathematics, can I have the query return only #topic or #note and #cat only, etc? when I return Tag I get all tags listed and sometimes I only want to see a certain category of tags.

One more question, is it possible, when returning a list or table to not include the file name? I have “Title” which returns the title and is preferred over the file name.

Hi.

I think some of your questions have an answer in plugin documentation. (I don’t pretend to be “rude” :slight_smile: , just an extra information because sometimes people don’t know the plugins github pages and, in some cases, the respective support documentation)

https://blacksmithgu.github.io/obsidian-dataview/

About your last question, by default tables have as first column the “File” or “Group” (if using "Group by…). But you can change this. If you use something like this:

```dataview
TABLE WITHOUT ID field1, field2 AS "other title"
...
```

I.e, using the expression TABLE WITHOUT ID. (In lists: LIST WITHOUT ID)

One last point. By default the first column is a file link, not a file name. So, if you want to add as first column your field “Title”, this is a link or just a string? If just a string you lost the link to the “source” note. If you want to use the field “Title” (a string) as a link to your note, you need to use a function link(path, [display])… in your case:

```dataview
TABLE WITHOUT ID link(file.link, Title) AS "your column title", field2 ...
...
```
2 Likes

thanks, I did read a lot so far, but I’m a bit new to the more technical stuff, esp. w/ code which is a bit over my head. That said, though it’s a steep learning curve, but learning a lot. really appreciate the help and don’t think you’re being rude… btw, do you know if my prev. question about the output of tags is all or nothing? I will start researching myself, but maybe you know this off the top of your head. cheers and happy holidays.

About your “tag” question, there are two points to consider:

  1. file.tags vs file.etags.
    If you have “#cat/philosopher” in one note, file.tags gives you as output an array of “#cat” + “#cat/philosopher”, i.e., parents and childs (as said in documentation, «subtags are broken down by each level»).
    file.etags gives you the exact tag, i.e., «an array of all explicit tags in the note». In example case, “#cat/philosopher”.
  2. A different thing is how to filter what you want to see. This implies a second level of interaction with results: not a source definition or a filter to apply but a kind of “magic” on what you want to see.
    For your case I think you can use the function regexreplace(string, pattern, replacement)… How to use it? The idea is hide all after (including) the “/”, using regex “magic”.
    I don’t know “regex” language and I’m new too in all this things. My method is just search and try things… And I found a regex code to define how to “remove all after something”…
    So, try this:
```dataview
TABLE ..., regexreplace(file.etags, "\/.*$", "") AS "Tags"
...
```
3 Likes

very interesting, and lots to figure out, but at least now I kind of know some of the ways to think about. really appreciate it!

p.s. this last bit of code to list the note title works great!

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