How to output only the number of records in a dataview query?

No tables or lists, just a only one number with the number of records that satisfy the query

One way to do this is the following:

```dataviewjs
dv.span((await dv.tryQuery(`
  LIST LIMIT 10
`)).values.length)
```

Where you replace the query in the middle with whatever query you want to count. This variant has no checks what-so-ever that your query actually do something sensible, so it assumes the query to be correct. :smiley:

1 Like

It works))) But only I wanted the number of records to be in one line with the header (#), for example as here:

Count of records 10

Then I expand the header and see the result of the same query in a table or list, as I understand this is not possible ?

You could replace the dv.span() with a dv.header(...) with extra text, but you’ll need another query when using headers like that.

It could however be possible to use one query to produce a collapsed callout with the query result inside the callout…

I can try that later today (or tomorrow) if you don’t figure it out.

With dv.header( I cant get the same respod like after dv.span(

Try something like:

```dataviewjs 
dv.header(2, "Count of  records " + (await dv.tryQuery(`
...
`).values.length)
```

tryed this

dv.header(2, "Count of  records " + (await dv.tryQuery(`
LIST LIMIT 10
`).values.length)

got many errors

Evaluation Error: SyntaxError: missing ) after argument list
at DataviewInlineApi.eval (plugin:dataview:18404:21)
at evalInContext (plugin:dataview:18405:7)
at asyncEvalInContext (plugin:dataview:18412:16)
at DataviewJSRenderer.render (plugin:dataview:18436:19)
at DataviewJSRenderer.onload (plugin:dataview:18020:14)
at e.load (app://obsidian.md/app.js:1:1167250)
at DataviewApi.executeJs (plugin:dataview:18954:18)
at DataviewPlugin.dataviewjs (plugin:dataview:19559:18)
at eval (plugin:dataview:19478:124)
at app://obsidian.md/app.js:1:1222590

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