Dataview plugin snippet showcase

Hi, I couldnt find an answer to my question though it might be pretty basic. Is there any way to obtain the sum of a column in dataview? (or an average)

Have a look in the documentation for sum(array) - Functions - Dataview

I’ve not used it myself…

Is there a way to have length with inline dql ? To display the number of inlinks for example.

here is one of my inline formulas for my weekly note with Days:: field for each daily note.

  • Weekly Sleep Duration Average calculation: =round(sum(this.days.sleep-duration)/length(this.days), 4)

is this what you mean?

2 Likes

Exactly thanks !

Do you know if it’s possible to do query with inline dql ? To get the number of documents with tag “#…” ?

Hi @Hydro, no I don’t know how to do that, but it would be interesting to know if it is possible.

With the help of @mnvwvnm, I did however update the inline expression for my average sleep duration in my weekly note. I was having problems with null errors when either I hadn’t made a daily note or hadn’t entered data into the sleep duration field. The code was trying to divide by fields containing the number 0, or something like that.

Now the code filters out those fields. And it only include data from daily notes which contain an actual number in sleep-duration. So if I haven’t made a daily note for some of the days this week, or haven’t entered a number, the formula will filter out and calculate the average sleep duration.

  • Weekly Sleep Duration Average calculation: =round(sum(filter(this.days.sleep-duration, (p) => p)) / length(filter(this.days.sleep-duration, (p) => p)), 2)
1 Like

In the weekly note under sleep and energy tracking in the table is choice(physical-activity, “:white_check_mark:”, “:x:”) as “Physical Activity”, where does this info comes from? I don’t see it in the daily note.

I have this large table:


However, it’s not showing all the entries, only about 2/3 of the ones I expect.
I have this list to keep track of which ones are there and which are not:

  • [ ] Antstorm
  • [ ] Applestem
  • [ ] Ashflower
  • [x] Barkpaw.
  • [x] Birch.
  • [ ] Blackjack
  • [ ] Blackwing
  • [x] Blossomstar
  • [x] Cedarpelt
  • [ ] Cherryflame
  • [x] Cinderkit
  • [x] Cinders
  • [ ] Cloudheart.
  • [x] Dawnstrike
  • [ ] Fallenblaze
  • [ ] Firewhisker
  • [x] Fishkit.
  • [ ] Flamepool
  • [x] Flowerpaw
  • [x] Foxwhisker
  • [x] Goldenpaw
  • [x] Greyfrost
  • [x] Hatchbelly
  • [x] Hazelkit
  • [x] Holly
  • [ ] Kestrelsky
  • [ ] Lakespring
  • [x] Leafkit
  • [x] Leopardtail
  • [x] Lionfrost
  • [x] Littlepaw
  • [ ] Logpelt
  • [x] Marshpelt
  • [x] Mottlespots
  • [x] Mouseclaw
  • [x] Mouseslip
  • [x] Muffin
  • [ ] Nightpaw
  • [ ] Oakkit
  • [x] Orchid
  • [ ] Petalkit
  • [x] Petalwhisker
  • [ ] Plumbird
  • [ ] Rainstar
  • [ ] Ravenpaw
  • [ ] Ripplewater
  • [x] River.
  • [x] Robin
  • [x] Rosepaw
  • [x] Rowaneye
  • [ ] Sandpaw
  • [ ] Shadow.
  • [ ] Shimmerpaw
  • [x] Shrewstar
  • [x] Silverkit.
  • [x] Silvernose
  • [x] Snakepaw
  • [x] Specklepaw
  • [ ] Spiderflower
  • [x] Splash
  • [x] Spottednose
  • [x] Stormkit
  • [x] Sunstar
  • [x] Tallhawk
  • [ ] Tansydapple
  • [x] Vixenlight

It was generated using the exact same code as for the table, only omitting the table jargon. I just copied it from the generated list, then converted it to a checklist and checked the ones visible. It seems there is no order to them being removed, though there might be a correlation between the removed notes and them linking to not yet created notes. But it’s not complete nor exclusive, so I don’t believe they’re related.

I’m completely lost on this. Does anyone have any insight?

1 Like

Not sure if you have been experiencing the same issue on your end, but the =[[<% tp.date.weekday("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>]].to-improve and likes were not functioning as expected on my end. I replaced the code with =[[<% moment(tp.file.title, "YYYY-MM-DD").subtract(1, 'days').format("YYYY-MM-DD") %>]].to-improve and now all works swimmingly.

Hi @Wan,
Yes, you’re right, it should have been tp.date.now, as in =[[<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>]].to-improve

but I have updated the templates on my GitHub the “temporal fields” to include the “sibling” time period, so Yesterday, or Last week/month for the weekly/monthly notes.

Hi @Saorsa, just paste - Physical Activity:: somewhere in your daily periodic note template.

You could either enter a boolean true / false, or just gibberish… or maybe you want to track some specifics “5 km run / 30 min swim / bushwalk with friend”.

You could then make a separate table in the weekly review to look at that detail.

dataview
TABLE  WITHOUT ID file.link as Date, physical-activity as "Physical Activity"
FROM outgoing([[#]])
where physical-activity 
where week = this.file.link

^It works perfectly fine, but I don’t really like the last line of the code above because it makes it a little bit more fragile. It relies on an outgoing condition and an incoming condition. I would rather if the last where was the equivaent of the inline expression =this.days.physical-activity. I’ll update when I know how to fix this.


  • Edit - Improved table using flatten, which allows us to filter to only the outgoing links from the “days” field in the weekly note. This code would break if a non-link string was in the “days” field.
TABLE WITHOUT ID days as Date, days.physical-activity AS "Physical Activity"
WHERE file.path = this.file.path
FLATTEN days
SORT days
WHERE days.physical-activity != null

If I can properly understand flatten, I think it will bring me some other useful tricks in the future!

1 Like

Thank you!!

Hi,

I wanted to have an overview of my current projects and their progress.

So I have notes representing projects which I tag with #current_project in the front matter:

---
tags: #current_project
---

Then I list them with Dataview, printing a filled circle for each completed task and a hollow circle for each incomplete task:

dataview
LIST replace(replace(replace(string(map(file.tasks.completed, (t) => t = true)), "true", "●"), "false", "○"), ", ", "") FROM #current_project

Here is an example:

Screenshot 2022-01-20 at 17.22.06

Simple and useful, I think :slight_smile: .

(Can undoubtedly be implemented more simply with JS, but I’m not there yet.)

6 Likes

Hi @PorcoRosso I like this a lot. You can simplify your statement by doing the following:

LIST
join(choice(file.tasks.completed, "●", "○"), "")
FROM #current_project

No need for Javacript, and it’s a little bit easier to read I think.

join function

choice function

12 Likes

Cool @dugdun , that’s very elegant. Will use that instead :slight_smile: .

1 Like

Hello! thank you both for this idea and showcase, it’s a very interesting concept and very intuitive to implement.

I was wondering, is there a way to increase the resultant size of “●”, “○” that @dugdun is using in his dataview?

Hi @stfrigerioj remember that the dots are just regular characters being displayed. If you want, you can use inline styles to change the size of those. Something like the following would make them 1.5 times bigger than they normally would:

LIST
join(choice(
	file.tasks.completed,
	"<span style='font-size:150%;'>●</span>",
	"<span style='font-size:150%;'>○</span>"
), "")
FROM #projecta

You can use any type of CSS styling that you would like.

7 Likes

Wow this is awesome! As a newbie with css, these insight are priceless. Thank you so much for your help

1 Like

Part showcase, part question: I am trying to create something like the Tag pane core plugin but inline and filtered for creating a dynamic MOC index of tags meeting a regex criteria.

Here is a tag index dataview code that I found here (thanks @mnvwvnm !) that I sparsely modified to list in alphabetical order.

TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") 
AS Tags, join(rows.file.link, ", ") AS Files FROM "" 
WHERE file.tags 
FLATTEN file.tags AS tag 
GROUP BY tag 
SORT rows.tag ASC 

Q: How do I modify this to filter by the #tool tag and subtags? (Using WHERE contains(file.tag, “tool”) or similar doesn’t work because it also grabs all of the other tags referenced in that file.

4 Likes

If I understand correctly… try this:

```dataview
TABLE WITHOUT ID (tag + "(" + length(rows.file.link) + ")") AS Tags, join(rows.file.link, ", ") AS Files
WHERE file.tags 
FLATTEN file.tags AS tag
WHERE contains(tag, "tool")
GROUP BY tag 
SORT rows.tag ASC
```
7 Likes