Dataview query WHERE contains list property

What I’m trying to do

I’d like to query my vault for notes containing the value “My Project” in the property “project” (that is a list) and grouping and sorting by “type” (another property)

Things I have tried

This code works:

TABLE WITHOUT ID
priority as "!!!",
file.link as Title,
file.ctime as CREAT,
file.mtime as MODIF,
project
FROM ""
WHERE contains(flat(list(project)), "2025 - Libro distopie")
SORT priority ASC
LIMIT 10

but if I change it to the following I get no results

TABLE WITHOUT ID
priority as "!!!",
rows.file.link as Title,
file.ctime as CREAT,
file.mtime as MODIF,
type as TYPE
FROM ""
FLATTEN type as T
WHERE contains(flat(list(project)), "2025 - Libro Distopie")
GROUP BY type
SORT default(((x) => {
"litnote": 1, 
"hub": 2,
"zettel": 3
}[x])(Type), "99") ASC
LIMIT 5

The lines “FLATTEN…”, “GROUP…” and “SORT…” have been used in other queries and they work but they don’t when combined in this one. What am I missing?

The second issue is about the value in the project property: if it is a simple string (like the one above) the query returns results, but if I change it to a link (“[[2025 - Libro Distopie]]”), again, I get no result, what’s wrong? :thinking:
Thanks!

After you’ve done the GROUP BY then all the fields have been grouped together into the rows object, and the grouping expression is stored in key.

In particular this means that you need to change the TABLE ... (before the FROM line) where you define the columns in your table to use either key or rows.???, and similar on all lines after the GROUP BY statement.


So try changing your file.ctime to rows.file.ctime (and so on), and change the SORT statement to something like:

SORT default(((x) => {
  "litnote": 1, 
  "hub": 2,
  "zettel": 3
  }[x])(key), "99") ASC

My bad @holroy, the solution was very obvious but I didn’t see it!
As for my second question about the WHERE clause searching for a link ([[…]]) I managed like this, in case somebody is interested:

WHERE contains(flat(map(project, (p) => link(p))), link("2025 - Libro Distopie"))

Don’t know if it’s the more elegant solution but it works!
Thanks

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