Dataview query for total number of notes with specific YAML parameter

Things I have tried

Looked through the forums but can’t seem to find a working solution. I am able to successfully do an inline query that counts number of notes where a certain tag appears, but am not able to count notes for specific YAML parameters.

What I’m trying to do

Apologies as I’m new to Dataview and have little to no coding knowledge. After using Obsidian simply (just making notes on my projects) for months I’ve amassed a lot and would like to be able to count notes based on YAML frontmatter specified.

Sample frontmatter:
tag: Project
ProjectName: Spiderman
Value: Mind

I would like the dataview query to return the total number of notes whose ProjectName = “Spiderman”.

When I type $= dv.pages("#Spiderman").length it returns to me the total number of notes with “tag: Spiderman” (which do not exist since Spiderman is under the parameter ProjectName and not tag)

Help would be greatly appreciated as my workflow revolves around knowing how many notes there are per YAML parameter.
Thank you in advance.

1 Like

Hi @ninjannette, welcome to the community!

If I understand your request correctly, you’re asking for an inline DataView query that counts how many pages have a YAML field of ProjectName with the value “Spiderman”. I recommend a query like the following:

`$= dv.pages().where(page => page.ProjectName == "Spiderman").length`

Let’s break this down:

  • dv.pages(): retrieves every page in your vault.
  • .where(page => ...): narrows down the list to pages that meet the following criterion:
  • page.ProjectName == "Spiderman": The ProjectName YAML field can be accessed as a property of the page object.
  • .length: Finally, return the number of pages that met the criterion.

Finally, here’s a working example:


Thank you so much! I couldnt figure out the syntax to specify a YAML parameter and you showed it here as .where(page =>page. =="").length. Thanks again! This will be very helpful for my workflow.


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