Sorting Dataview groups

Why does this query return the date groups in an unsorted order?

LIST rows.file.link
SORT file.mtime DESC
LIMIT 50
GROUP BY dateformat(file.mtime, "DDDD")

I’m just trying to get a list of recently modified files grouped by date, in reverse order.

Thanks.

Following the solution give on this forum thread, I managed to sort the groups by using AS before a second SORT operation:

LIST rows.file.link
SORT file.mtime DESC
LIMIT 25
GROUP BY dateformat(file.mtime, "yyyy-MM-dd") AS Date
SORT Date DESC

However, I can’t use the DDDD date format anymore (otherwise all “Mondays” appear before all “Wednesdays”, sorted alphabetically).

Is there a way to sort the groups by one date format (yyyy-MM-dd) while dislplaying the group names as another (DDDD)?

Thanks.

Here is a hack which seems to accomplish what you want:

```dataview
LIST rows.file.link
SORT file.mtime DESC
LIMIT 25
GROUP BY dateformat(file.mtime, "%%yyyy-MM-dd%% DDDD") as Date
SORT Date DESC
```

It’s utilising the sortable date format within a comment so that it doesn’t show, with the shown date format appended afterwards.


I was not quite sure why we couldn’t just use the SORT dateformat(file.mtime, "yyyy-MM-dd") DESC directly, but then I remembered that you are doing GROUP BY which moves each of the (identical) file.mtime’s into rows.file.mtime, so then I tried the following query:

```dataview
LIST rows.file.link
SORT file.mtime DESC
LIMIT 25
GROUP BY dateformat(file.mtime, "DDDD") as Date
SORT dateformat(rows.file.mtime[0], "yyyy-MM-dd") DESC
```

This lifts the first file.mtime in the group by set, and reformats it to something usable by the sort algorithm, and this does indeed work as intended. So the hack above is not needed anymore! :smiley:

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