Dataview: how to "combine" two filters query

Hi all,

What I’m trying to do

I want to filter all the notes in a vault using two criteria: the first is the actual creation date of the file (file.ctime.day), while the second is the file name. Basically, I want to display all the notes created in past years on the same month and day as today in a table, and so far I’ve been able to do this, but only with two separate queries.

Things I have tried

On one hand, I have correctly filtered all the notes that start with ‘yyyy-mm-dd’: this query works, and this is the code:

TABLE WITHOUT ID file.link as "Titolo", substring(file.name, 0, 4) as "Anno"

from ""

where contains(file.name, dateformat(date(today), "MM-dd"))

  and substring(file.name, 0, 4) < dateformat(date(today), "yyyy")

sort substring(file.name, 0, 4) desc

On the other hand, I also filter all the notes that have file names different from ‘yyyy-mm-dd’, like this:

TABLE WITHOUT ID file.link as "Titolo", dateformat(file.cday, "yyyy") as "Anno"
FROM ""
WHERE file.ctime.month = date("today").month AND file.ctime.day = date("today").day AND file.ctime.year != date("today").year
SORT file.ctime.year DESC

Everything works correctly, but I obviously get TWO tables. I would like the two filters to create a single table. Given the logic of how the first filter is built, I cannot add an ‘OR’ to the ‘WHERE’ line and then copy the second criterion, because otherwise, in the ‘YEAR’ column, I will see the first four letters of the file name, not the actual creation year of the note, which should instead be extracted from ‘cdate’.

Can someone help me?

Solved :slightly_smiling_face:

TABLE WITHOUT ID file.link as "Titolo", 
  choice(contains(file.name, dateformat(date(today), "MM-dd")), substring(file.name, 0, 4), dateformat(file.cday, "yyyy")) as "Anno"

FROM ""

WHERE (contains(file.name, dateformat(date(today), "MM-dd")) AND substring(file.name, 0, 4) < dateformat(date(today), "yyyy"))
   OR (file.ctime.month = date("today").month AND file.ctime.day = date("today").day AND file.ctime.year != date("today").year)

SORT choice(contains(file.name, dateformat(date(today), "MM-dd")), substring(file.name, 0, 4), dateformat(file.cday, "yyyy")) DESC

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