Compare templater variable to frontmatter value in dataview query where clause

Hi folks.

I’ve looked at the Dataview docs and numerous examples, but I am still stumped as to how to make the where clause comparison.

I’d like to compare frontmatter data in my daily notes that contains a Week of the Year value to the current week generated in a templater block as a where clause filter in a dataview. I am just baffled as to how I do this in Dataview.

I currently have daily notes with the following frontmatter data

---
Create Date: 2022-10-24
Week: 44
---

In my weekly template, I have the following code

<%*
var todayDate = tp.date.now("YYYY-MM-DD")
var todayString = tp.date.now("dddd, MMMM Do YYYY")
var mondayDate = tp.date.weekday("YYYY-MM-DD", 1)
var mondayString = tp.date.weekday("dddd, MMMM Do YYYY", 1)
var fridayDate = tp.date.weekday("YYYY-MM-DD", 5)
var fridayString = tp.date.weekday("dddd, MMMM Do YYYY", 5)
var week = moment(todayDate, "YYYY-MM-DD").week()
await tp.file.rename("Weekly Note-" + mondayDate + "-" + fridayDate)
-%>

What I’d like is something like

```dataview
LIST WITHOUT ID Advisories
FROM "daily notes"
WHERE Advisories!="None" 
AND -> Frontmatter week is equal to templater variable week <-
FLATTEN Advisories as Advisories

If anyone can please point me in the right direction, I'd really appreciate it. 

Regards,
Bruber

In each daily note you create frontmatter fields for date and week of the year.
In dataview you don’t need the week field because you can “extract” the week from the date.
But I don’t understand one point: if you use this templater code only to change the file name in your weekly note, why you don’t create a frontmatter field at same time with one valid value to extract the week number? Today date?
Or I’m missing something…

Hi @mnvwvnm and thanks for the reply.

  1. I can create a frontmatter value in the weekly template to hold the week easily enough.
  2. I’m still not getting how to do the comparison in the where clause, even if it’s comparing the daily frontmatter week to the weekly frontmatter week

Thanks,
Bruber

Let’s say you have in your daily notes this:

---
Week: 44
---

And in the weekly note

---
Week: 44
---

In you dataview query placed in the weekly note you can use:

WHERE Week = this.Week

If your weekly note is in the same daily notes folder, then you’ll see also the weekly note (to remove it you can use WHERE file.path != this.file.path)

You can also work with the date value.

Daily notes:

---
Create Date: 2022-10-24
---

Weekly Note:

---
Create Date: 2022-10-30
---

Then you can use something like:

WHERE row["Create Date"].weekyear = this["Create Date"].weekyear

or

WHERE create-date.weekyear = this.create-date.weekyear

Once again, if weekly note in same folder, you need to exclude it with the clause above.

(An extra note: dataview works with Luxon/ISO format, different from moment format in Templater. As consequence, you’ll note some differences in the week number. For example: for date 2022-10-24 Templater gives you the number 44, dataview week year gives you 43)

Thank you again for the help. I swear I tried

WHERE Week = this.Week

but it didn’t come back with anything. Now it’s working.

I also appreciate the additional guidance on using the create-date.weekyear. and row comparisons. I am really new to Obsidian but it has cut my end of week work down significantly in just one week of use.

Regards,
Bruber

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