Dataview plugin snippet showcase

You can use dataview to do rollups, several levels deep.

Example:

```dataview
table start-date, end-date, quarters, quarters.months.weeks.start-date
from #years
sort date asc

In my pages tagged #years I have a list of related quarters in link format:

Likewise, in my quarters pages I have a list of linked months:

And so on. The above query will produce a column that has all the start dates of all the weeks that are related to the months that are related to the quarters that are related to the year for that row.

Small example:

This isn’t maybe the most useful example, but I wanted to show a few levels of depth. Anyone familiar with rollups knows this opens up some really cool stuff, especially for reviews and such!

12 Likes

This is awesome! I really like how you can dive deep into it :grinning_face_with_smiling_eyes:

I see blacksmithgu has just added more support weeks:

image

Perhaps you can use this to reduce some of the noise in how the dates are rendered on the right side there.

3 Likes

Good point! I’ll need to check those out. Lots of new goodies this week :heart_eyes:

1 Like

I’m not sure if this way always possible, or just recently added, but you can create indented lists when a note’s field is an array.

For example, show a list of all literature notes, with a sublist of authors from each:

list authors from #LitNote

image

4 Likes

This feature seems to have alot of potential, but I don’t think the example in the docs works as at 2021-03-24. The following is what I found to work.

You can add strings and fields to the result of a list query.

For example, in each university assignment, I have the type of assignment, as well as a field intensity with a green, yellow, or red square indicating how much effort will be required of me:

---
intensity: :green_square:
type: ‘Essay’
---

Then, using + as a concatenation operator, you can write a string containing field values:

list "This much work " + intensity + " required for the " + type 
from #Assignment

image

12 Likes

You can now also very easily create a list of backlinks:

list from [[note]] // List all notes which link to [[note]]

Or an index of all links leaving a note:

list from outgoing([[note]]) // List all notes that [[note]] links to

Coupled with the Templater plugin, you can create a template to quickly insert into any note:

# Backlinks

```dataview
list from [[{{tp_title}}]]
```
# Index

```dataview
list from outgoing([[{{tp_title}}]])
```
28 Likes

This might be very basic, but can I have the results published transcluded? So instead of the list produced being [[File_name]] it would be ![[File_name]].?

7 Likes

Not currently, no. If this isn’t already a feature request, I think it’s a great idea to post!

3 Likes

I’ve been looking all over for how to query around nested tags.

For instance, I may have a bunch of notes to aggregate Standard Work for my teams, but those will have nested tags. For a MOC page, I may want to create a list of all the Standard Work pages I have in my vault, inclusive of all of the nested tags. A way I would think I could write that is:

list from #standard-work/**

But I can’t find an ergonomic way of writing a query like this which doesn’t require me to where-clause against every known case of nested tag which is more static than I’d like. (I don’t want to update this page every time I add a new nested tag).

Any thoughts in the community?

2 Likes

Just to clarify, your questions says “I may want to create a list of all the Standard Work pages I have in my vault, inclusive of all of the nested tags”. So you want to list every page tagged with #standard-work and also every page tagged with #standard-work/something/maybeMore?

This snippet should do that:

list from #standard-work

Dataview already matches nested tags, so that list from #Tag should match #Tag as well as #Tag/sub

This ability to add the Backlinks and Index is awesome! Thanks.

3 Likes

Has anybody tried the GROUP BY? I tried that but didn’t get the expected result.
For example, say I have some notes with the tags #Note/Author, #Note/Principle, #Note/Concept…how can I group all the results with tag #Note according to their subtags?
Could anyone help?

2 Likes

I actually hadn’t figured it out myself, but your question made me give it a go. I think I’ve got it…

So, I’m gonna use an example:

In each of my assignments, I have a field (intensity) with a red, yellow, or green square telling me how much work will be required.

image

So, if I want to group all of my assignments by their intensity, I do the following.

First, gather all the assignments:

FROM #Assignments

Then, group by intensity:

GROUP BY intensity

rows Object

Now, here is the part that confused me… by grouping them, you’ve now got a new object created by the grouping. This is a nested list of all the assignments grouped by intensity. So something like:

[
[A1, A2, A6], // Green
[A3, A4], // Yellow
[A5, A7] // Red
]

The way you access this new list is with the rows object.
So if I want the file name of every note in the array, I call rows.file.name.
If I want the dueDate of each note in the array, I call rows.dueDate.

In this example, I call the title property (rows.title).

Now, you sorta have to change the ordering around, but it should still make sense.

TABLE intensity, rows.title 
FROM #Assignment
GROUP BY intensity

Which gives me this, as desired:


So for your example, you want to group files by subtag. Can you try this and let me know what you get? I think the output will be a little messy, because it repeats alot of the tags, but it should still group them as you want.

TABLE rows.file.name, rows.file.tags
FROM #Note
GROUP BY file.tags

Also, it will only consider two notes to be in the same group if they have exactly the same tags. So even if two notes have #Note/Author, if the one has a tag that the other doesn’t, I don’t think they’ll be grouped together.

25 Likes

wow @SkepticMystic Thank you so much for your elaborate and earnest answer! It does help a lot!
It is the rows Object that confused me too, and you’ve made it so clear. I tried replacing the rows.file.name with rows.file.link under your instruction, and now it works quite perfectly.
Just to let you know you helped me solve the long time problem.Thanks so much again! :kissing_heart:

4 Likes

Is there a way to show the number of result rows ?

I’m really glad to hear it helped! :grinning_face_with_smiling_eyes:
Thank you for getting me to finally figure out how group by works :joy:

2 Likes

I tried a hacky method which didn’t seem to work.
I thought to use length() or sum(), but each of these only works as a test in a where block; it doesn’t give a returnable value.

I think this would be really useful though. Check if it’s an existing feature request and give it an upvote, otherwise make a new post for it :slight_smile:

3 Likes

For now, you could totally pair dataview with the Obsidian Query Language plugin (OQL).

After your dataview table/list, put an OQL codeblock underneath it to show the {count} of the same query.


Source

11 Likes

Thanks a lot for your help.

I also tried to play with Group By and ‘sum’ and ‘length’ functions but like you said, it doesn’t seems to work in this context.

I thought that OQL’s queries only rely on folders… I will check the doc again to see if it works also with yaml frontmatter metadata.

1 Like

I haven’t used OQL very much, so its definitely possible that it doesn’t allow querying on the same objects as dataview.

But I think this would be a useful feature to request in a future update :slight_smile: