Dataview: Sorting Rows with Groupby

What am I trying to do

I am trying to sort the output generated using GROUP BY in dataview query based on output against each row for that particular group.

Things I have tried

This is the query that I have prepared:

TABLE rows.file.link as "Files", rows.file.mtime as "Last Update"
from "File/Project A"
group by slice(split(file.folder, "/" ), -1) as "Folder"
sort "Last Update" desc

Explanation

Path File/Project A has multiple folders, say, A.1, A.2, A.3, etc.
Each folder will have multiple notes inside that folder.

What I want is to generate the list of notes inside each folder (group by folder) which are arranged in descending order of the updated dates for those notes. (That is, the notes inside each group will be sorted in descending order of mtime.)

Sequence: 1) Group by 2) Sort notes inside each group

How to achieve this?

To sort something within a group: sort first, then group. So:

```dataview
TABLE rows.file.link AS "Files", rows.file.mtime AS "Last Update"
FROM "File/Project A"
SORT file.mtime DESC
GROUP BY slice(split(file.folder, "/" ), -1) AS "Folder"
```

So you know for next time, using AS display-name in a column header doesn’t assign a value to display-name. That is, it’s not a variable, just a string for displaying. So you wouldn’t have been able to reference “Last Update” anyway. (Whereas a FLATTEN x AS y does assign to y the values from array x).

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