Dataview sort tasks by due date when grouped by file name

Query 1 below finds all uncompleted tasks in my vault and sorts them by due date.

Query 2 is the same query but with the tasks grouped by their file name. In this query, sorting by due date doesn’t work, even if the files containing the tasks only have one task each.

Possible to sort by due date when grouped in this way?

# Query 1 
```dataview
TASK
FROM
	""
AND
	-#excludefromtodoqueries
WHERE
	!completed
SORT
	due
	ASC
```

# Query 2
```dataview
TASK
FROM
	""
AND
	-#excludefromtodoqueries
WHERE
	!completed
GROUP BY
	link(file.name)
SORT
	due
	ASC
```

With thanks for any pointers or solutions … I have tried countless permutations.

1 Like

I’ve not tested this, so it’s my wild guess :crazy_face:, but what happens if you do:

SORT min(rows.due) 

Or possibly max(), in some combination with asc/desc. Does that fix your sorting issue?

1 Like

This works perfectly, without the ASC.

SORT min(rows.due)

As does this, with the ASC:

SORT min(rows.due) ASC

I have read the manual for functions but it would have taken me an aeon or two to think to apply min(a, b, ..) in this way.

Very grateful for the help. Yet more to read and learn.

THANKS :person_gesturing_ok:t4::bowing_man:t4::+1:

1 Like

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