Combining Backlinks and Date Field

What I’m trying to do

In my Daily Note files, I would like to have a dataview table which shows;
a) Notes that have the same date metadata value as the daily note’s date and
b) The Backlinks to said daily note.

I have been able to do both of these separately, but I’m not sure how to combine them together.

Things I have tried

Ok, so on one hand I have this;

TABLE Without ID as "Files associated with this day"
WHERE PentDate = date( and PentDate != nil

Where the PentDate field is in the same format as the Daily Notes (of YYYY-MM-DD)

And something like this;

Table Without ID as "Instances of [Thing]"
FROM [[]]

But I don’t know how to combine both of these, or if it is even possible.

Have you tried the combination? And don’t that work (or not work)?

Not tested, but if both of your queries work, then the combination should look something like:

TABLE Without ID as "Files associated with this day"
FROM [[]]
WHERE PentDate = date( and PentDate != nil

Yeah I guess this is the thing that I strictly asked for – but no, what I’m after is to show both sets of results rather than the intersection of both

Using this code means that I show [files that have the specified date value] AND [which are backlinks to this file], however I’m actually wanting the operator to be “OR” instead of “AND”

Anyway, thank you for your response.

My bad, I read your combination as the combination of the criteria and not the combination of result sets. The reason why my query doesn’t include both criterias is that FROM limits the set of files seen by the WHERE clause.

In a larger vault it would be advantageous to use FROM to limit the file set before the WHERE does the finer selection. Imagine a file set of thousands of files, but your candidate file set for a given query is only a few hundred. If possible doing the FROM first could then make the overall query run a lot faster, as the WHERE only needs to check the limited candidate set.

However, to make your query work we need to look at alternatives form of how to do FROM [[]]. This clause essentially means any files that links to the current file (aka this.file). This also means that there is an outlink from this.file to said file, and that there is an inlink from file to `this.file. As such the following statements are the same:

  • FROM [[]]– With the advantage of limiting the file set
  • contains(this.file.inlinks, – Checks whether a candidate file is in the list of links towards this.file
  • contains(file.outlinks, – Checks whether the candidate file has an link going outwards towards this.file

Given a case of a MOC, it’s reasonable to assume that the inlinks of that MOC is far outnumbered by the number of outlinks from any given file. As such, it’s slightly better (when we need to look at all the files anyways) to do the check on the outlinks instead of the inlinks.

All this rambling leads to the following query:

WHERE contains(file.outlinks,
   OR ( PentDate AND PentDate = date( )

NB! Note that when you’re doing OR with a filter of multiple elements, be sure to put parentheses around that statement as in the query above. I tend to write such OR statements with one (combination) set on one line, and then making sure it has the parentheses around the entire line.

Thank you so much for your time and response, this is exactly what I wanted.

I have been able to impliment that solution, but I did change it over to a table (which I just prefer the look of more than a list)

Also, thank you for the extra information going into detail about optimisations and alternatives. I also like how you format the OR line, to be it’s own line, makes it way more readable.

1 Like

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