Display count (number of rows) that a dataview query returns

Dear fellowship of Obsidian,

I have following query to list the notes that don’t have a link to any daily note:

TABLE WITHOUT ID
	length(rows.file.link) AS Total  
	FROM ""
	WHERE none(regexmatch("[0-9]{4}-[0-9]{2}-[0-9]{2}", file.outlinks.file.name)) 
	AND !contains(file.path, "90 - ")
	AND !contains(tags, "waypoint")
	AND !contains(file.path, "10 - ")
	AND !contains(file.path, "00 - ")
	AND !contains(file.path, "99 - ")
	AND !contains(file.path, "91 - ")
	AND !contains(file.path, "92 - ")
GROUP BY file.link

What I would also do, is to display in a different place the number of results (rows) like the count function in SQL.

Things I have tried

I have done many trial and error, looked up many forum pages, consulted the dataview documentation, but no luck. Don’t know what to do next.

my last try was something like this:

$= dv.pages().where(page => none(regexmatch("[0-9]{4}-[0-9]{2}-[0-9]{2}", file.outlinks.file.name))).length

What I’m trying to do

In dataview query, you can use this:

TABLE WITHOUT ID
	length(rows) AS Total  
	FROM ""
	WHERE none(regexmatch("[0-9]{4}-[0-9]{2}-[0-9]{2}", file.outlinks.file.name)) 
	AND !contains(file.path, "90 - ")
	AND !contains(tags, "waypoint")
	AND !contains(file.path, "10 - ")
	AND !contains(file.path, "00 - ")
	AND !contains(file.path, "99 - ")
	AND !contains(file.path, "91 - ")
	AND !contains(file.path, "92 - ")
GROUP BY true
2 Likes

You are my savior today ! Can’t thank you enough.

That will be very useful to me for other things also.
I think I will do it in dataviewjs to just construct a string like “X notes without a date reference” which will link to the list of notes.

:heart:

To output only a number, it’s better via dataviewjs.
I’m not versed in JS (as in any code… isn’t my field), but you can’t apply the same logic as in DQL.
For example, you can’t “follow” the link to target a specific metadata in the same way as file.outlinks.file.name. This doesn’t work in dvjs.
Another issue is the regex. I’m a regex dumb and I don’t know how to use it in js. But I ask you this: your daily notes have the title in format “YYYY-MM-DD”? if yes, I think you don’t need to use regex because in theses cases you have an extra implicit field: file.day. so, maybe you can use the exclusion of the files with the file.day data instead the regex…

Hi. I did it like this and it works like expected. I don’t know if i overdid it, but that’s what I’m going with right now :slight_smile:

```dataviewjs
const dataQtyNotes = await dv.query('TABLE WITHOUT ID length(rows) AS Total FROM "" WHERE none(regexmatch("[0-9]{4}-[0-9]{2}-[0-9]{2}", file.outlinks.file.name)) AND !contains(file.path, "90 - ") AND !contains(tags, "waypoint") AND !contains(file.path, "10 - ") AND !contains(file.path, "00 - ") AND !contains(file.path, "99 - ") AND !contains(file.path, "91 - ") AND !contains(file.path, "92 - ") GROUP BY true');

const rowsQtyNotes = dataQtyNotes.value.values;
const Total = rowsQtyNotes.map(b => b[0])[0];

if (Total > 0) {
	dv.paragraph('<br>Number of notes without date reference: **' + Total + '**');

	const dataList = await dv.query('LIST WITHOUT ID sort(rows.file.link) FROM "" WHERE 	none(regexmatch("[0-9]{4}-[0-9]{2}-[0-9]{2}", file.outlinks.file.name)) AND !contains(tags, "waypoint") AND !contains(file.path, "10 - ") AND !contains(file.path, "00 - ") 	AND !contains(file.path, "99 - ") AND !contains(file.path, "91 - ")	AND !contains(file.path, "92 - ") AND !contains(file.path, "90 - ") GROUP BY file.folder');

	const rowsList = dataList.value.values;
	dv.list(rowsList);
} else {
	dv.paragraph('All files have a date reference.')
}

You were right about file.day. I can ditch the regex.
Thanks.

Hi again, actually the file.day doesn’t work. It has to be the regex. But with it, and your help, everything works perfectly fine.

1 Like

About the file.day maybe any conflict with files with both conditions: file.day exists if tile contains the format “YYYY-MM-DD” OR if any date field with the key date or Date.

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