Sort next tasks query in reverse order (upcoming -> future)

I have a default journal query that shows tasks on journal pages for the upcoming seven days. It currently sorts in descending order so the tasks upcoming in seven days (Dec 21, Dec 20, Dec 19, etc) sit above those due tomorrow.

I’d like to reverse the sort order (eg Dec 16, Dec 17, Dec 18, Dec 19, etc). I’ve tried a few different things using result-transform but never been able to figure it out.

Query and a screenshot of the current behavior below. Thanks for any assistance!

   {:title [:h3 "📅 Next"]
    :query [:find (pull ?block [*])
            :in $ ?start ?next
            :where
            [?block :block/marker ?marker]
            [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
            [?block :block/page ?p]
            [?p :block/journal? true]
            [?p :block/journal-day ?d]
            [(> ?d ?start)]
            [(< ?d ?next)]]
    :inputs [:today :7d-after]
    :breadcrumb-show? false
    :collapsed? true}

1 Like

I don’t know if you need the page blocks or not, but this result-transform will do the sorting you are looking for. Except that it will just be a list of tasks.
:result-transform (fn [result] (sort-by (fn [h] (get-in h [:block/page :block/journal-day])) result))
image

2 Likes

@Siferiax Do you know how to sort by scheduled date AND time? I guess it would be as easy as add something like “:block/scheduled-time” to the (get-in) part. But I can not find anywhere the exact words.

This scheduled-time info has to be accessible, as the Agenda plugin is capable to sort tasks by time too.

Hope you can help me!

Not really. Unfortunately the only place it shows up is the :block/content aka the plain text of the block.
So technically you can extract it using regular expressions, but it isn’t easy or straight forward.
I’m sorry to say that at this time I cannot help you further with this due to time/energy constraints. (Hence taking so long to answer in the first place)