Dataview plugin snippet showcase

Hi, I also just saw this update announcement for v0.13.19
“- Fixed embeds not rendered in plugin code”

I’m on my mobile atm… But I’m interested to know if this Field:: ![[image.png]] will now work?!

This worked thanks! For the 24 hour time - if you have fall asleep past midnight (let’s say 2 am), I imagine you would subtract the awake hour from the time you fell asleep (aka. 26 in this case), and not 24, to get the duration right? Just double checking I’m doing this right

Does anyone know why I am getting this error Dataview: Error:

Here is what I have for my dataview query

table WITHOUT ID
FROM #habit 
WHERE week = this.file.link
sort file.name asc

This is what I get as a result

– PARSING FAILED --------------------------------------------------

1 | table WITHOUT ID

2 | FROM #habit
| ^
3 | WHERE week = this.file.link
4 | sort file.name asc

Expected one of the following:

‘,’, /FLATTEN/i, /FROM/i, /GROUP BY/i, /LIMIT/i, /SORT/i, /WHERE/i, EOF

I keep having problems on the FROM line, sometimes it happens with #hastags and sometimes when I am trying to pull from a folder

Hi again!
You’ll need some columns to render it as a table.

TABLE WITHOUT ID field_1, field_2
FROM #Habits

Or change it to a list of files, and with a list I think you can display one field next to the file name.

LIST Field_1
FROM #Habits

Hello,

Is there any way to display a subtag only in a dataview table ?

E.g. :

#Type/Status → Display only “Status” in the dataview table.

Thanks !

Hi @JamesKF, I have a two solutions you can try. The first solution assume you only ever have one tag for the note.

TABLE
	regexreplace(tags, "^Type.*/", "") 
	AS "Type"
FROM #status
SORT file.name

This will give you the last word of the tag if the word Type is at the beginning. It doesn’t work well if you have multiple tags.

For multiple tags here is a possible solution. It is more verbose.

TABLE
	join(
		map(
			filter(
				split(tags, ", "), 
				(t) => startswith(t, "Type")
			),
			(tag) => regexreplace(tag, "^Type.*/", "")
		),
		" | "
	)
	AS "Status"
FROM #Type
SORT file.name

The tags are joined back together to make a string using the | character, change this to a comma if you would prefer.

5 Likes

Thanks a lot @StuMaynes for your detailed answer. I will add a reference to your post in the topic I created for this question.

Obsidian charts

HI Please may I ask for some help please for my Table queries? I been trying to get it to work but am not getting very far. Thank you for your time.

I mark all my notes relating to a person by using [[@name]], and this convention is used through out my database in all of the notes. So there are notes linked to a person, or in this person’s notes, there may be outgoing links to other notes.

I want to create a People index (Table) using Dataview, one the first column showing the persons name, the second column showing all the notes that mentions this person, and the third column all notes that this person’s note mentions.

I got as far as generating the first column using:

Table dateformat(file.mtime, “dd.MM.yy-HH:mm”) as “Linked Notes”
WHERE contains(file.name,"@")
Sort file.name ASC

But not sure how to proceed next… can anyone help please?

Note: the dateformate was just a dummy i used to test… so it is just a placeholder… thank you…

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