Dataview plugin snippet showcase

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

5 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

13 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}}]])
```
31 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

1 Like

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.

32 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

16 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:

So your post got me thinking alot, and I think Iā€™ve figured out a workaround for seeing how many results get returned!

This CSS snippet will number the rows of a dataview table:

.table-view-table {
    counter-reset: section;
}

.table-view-table > tbody > tr > td:first-child::before {
    counter-increment: section;
    content: counter(section) ". ";
}

Resulting in something like this when you make a table:

12 Likes