Dataview table based on Date condition

I have a dataview table that queries all files inside a folder. inside each file there is a key representing a date. DATE::YYYY-MM-DD

I want the file’s query to be shown only if this condition is true: the DATA key should be earlier than today’s date.
I tried this code but it doesn’t work:

##TABLE 
##...
##FROM ...
WHERE DATE < date("today")

This works in local tests (but all vaults are different):

```dataview
TABLE 
FROM ""
WHERE date < date(today)
```
1 Like

Unfortunately, It has no effect on my dataview table:

TABLE WITHOUT ID
file.link AS Files,length(filter(file.tasks.completed, (t) => t = true)) AS Completed, length(file.tasks.text) as Total, "<progress value='" + (length(filter(file.tasks.completed, (t) => t = true)) / length(file.tasks.text)) * 100 + "' max='100'></progress>" AS Progress
FROM "FOLDER"
SORT IMPORTANCE DESC
WHERE DATE < date(today)

You’re using both DATA and DATE, so try do something like:

```dataview 
Table DATA, DATE, file.day
From "folder"
Limit 20
```

This could you help you verify that the data is what you expect it to be, and maybe help you find a solution.

1 Like

The query below works in any file in any folder in my vault.

If the DATE:: value is today’s date, the name of the actual note will not appear in the query.

If the DATE:: value is changed to being before today’s date, the name of the actual note will appear in the query (Dataview needs a few seconds to update).

Does it work for you?

DATE:: 2023-07-05

```dataview 
TABLE WITHOUT ID
file.link AS Files,length(filter(file.tasks.completed, (t) => t = true)) AS Completed, length(file.tasks.text) as Total, "<progress value='" + (length(filter(file.tasks.completed, (t) => t = true)) / length(file.tasks.text)) * 100 + "' max='100'></progress>" AS Progress
WHERE file.folder = this.file.folder
SORT IMPORTANCE DESC
WHERE DATE < date(today)
```

dataview example

1 Like

Your code works fine :+1:

I figured it out that the problem is caused by having multiple DATE keys instead of one in most of my files.

How can I query on the condition that at least one the values in the file is earlier than today’s date?

Like this:

TODAY’S DATE: 2023-07-08
FILE1
DATE:: 2023-10-10
DATE:: 2022-01-01
RETURN FILE1

FILE2
DATE:: 2023-10-03
DATE:: 2023-11-03
DON’T RETURN FILE2

Here is an example of three variants which all should work. The last example consists of the last column, and the FLATTEN statement.

```dataview
TABLE WITHOUT ID
  any(map(date, (d) => d < date(today))),
  filter(date, (d) => d < date(today)),
  any(earlierDates)
FLATTEN array(map(date, (d) => d < date(today))) as earlierDates
```

If you’d want to use this not only for display, but also for grouping or where clauses, I’d use some variant of the last one to repeat the condition.

The filter variation, opposed to the two other, returns just the matching date(s).

Note that in addition to any, it’s also possible to use none and all, for their variants in required values.

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