Dataview query that both excludes a file and an outlink

What I’m trying to do

I would like to create a note called Journal Entries that contains a table that has a column called date (which is actually the file name) and a column called mentions (which is actually file.outlinks).

Further, I would like to exclude the daily template file from the query AND exclude the “Yesterday” and “Tomorrow” navigation links. Lastly, not sure if this matters, but “Yesterday” and “Tomorrow” are aliases for other journal notes. i.e.

<< [[2023-05-29|Yesterday]] | [[2023-05-31|Tomorrow]] >>

Things I have tried

While I have the basic query working and have successfully excluded the Daily Template file

journal entrries

I cant figure out how to exclude the Yesterday and Tomorrow links. I am using the following query, and have tried adding AND statements excluding the Yesterday and Tomorrow outlinks, but no luck :frowning:

TABLE file.outlinks as "Mentions"
WHERE contains(type, "daily") AND !="Daily Template"

Also, apologies, but I can’t figure out how to do code blocks on this forum, I will edit for clarity if somebody can advise.

I’ll work on renaming the file column header later, that shouldn’t be too difficult I’m hoping.

Added code blocks per discussion on Discord. Good luck!

Much appreciated!

Is the following valid syntax?

TABLE file.outlinks as “Mentions”
WHERE contains(type, “daily”) AND !=“Daily Template” AND !contains(file.outlinks, "Yesterday") AND !contains(file.outlinks, "Tomorrow")

Assuming contains looks for that string and doesn’t require an exact match (which I think is accomplished by econtains), that should work right?

If that was legal syntax, that would totally eliminate entire files where either of the yesterday or tomorrow links existed. However, I don’t think that’ll work since file.outlinks is a list of links where you then compare them against a text value.

You’d rather want to do a filter() on the file.outlinks to remove those specific links. Potentially combined with some check to see if it’s anything left of the list. I can type up an example later on today, I think.

Ugh, you are right. I dont want to eliminate the file from the table, I want to eliminate the outlinks containing yesterday and today from showing in the output. Thanks f0r pointing that out.

Thank you for providing the next clue, I’ll have a look at the filter() functionality. I’m pretty ignorant of how all this stuff works, but I feel like I am making progress.

Thanks again, much appreciated!

So a nice person from reddit was able to help me out. Query follows:

TABLE filter(file.outlinks, (x)=> 
!contains(string(x), "Yesterday") AND 
!contains(string(x), "Tomorrow")) AS "Mentions" 

WHERE contains(type, "daily") 
AND !="Daily Template"

The documentation for the format function is available, but I was having problems wrapping my head around how to use it.

1 Like

Another option for that filtration could be to do:

filter(file.outlinks, (o) =>
    meta(o).display != "Yesterday" AND 
    meta(o).display != "Tomorrow" ) as "Mentions"

This pulls out the display variant of the link, and make sure it doesn’t equal neither “Yesterday” or “Tomorrow”.

Note that if you’d want either variant in combination with not showing entries without any mentions at all you need to do something like the following:

TABLE Mentions
FLATTEN array(filter(file.outlinks, (o) =>
    meta(o).display != "Yesterday" AND 
    meta(o).display != "Tomorrow")) as "Mentions"

WHERE contains(type, "daily") AND != "Daily Template"
  AND length(Mentions) > 0 

Notice the usage of array(filter( ... ) ) to repopulate the list after doing the FLATTEN on it, which is needed in order to store the result into Mentions. This usage of FLATTEN (and array(filter( ... ))) allows for the result to used in WHERE clauses (like above) and other parts of the DQL query.

1 Like

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