Possible to rename Dataview group headings after sorting them, and keeping the sort?

What I’m trying to do

I’m trying to build a query that is going to return my upcoming tasks for the week, grouped by day of the week. What I’d also like is for the group headings to be renamed to the day of the week rather than the ISO date. Example:

Monday

  • This is a task due Monday

Tuesday

  • This is a task due Tuesday

Wednesday

  • This is a task due Wednesday

Thursday

  • This is a task due Thursday

Things I have tried

I got the basic functionality down with this:

```dataview
TASK
FLATTEN text + " 🔗 " + file.link as visual
WHERE !completed and due >= date(today) and due <= date(today) + dur(7 days)
GROUP BY due
SORT due ASC

which returns what I want, functionally, just like above: tasks grouped by their date, and those groups listed in order. (I use the FLATTEN command to tack on a custom backlink, I don’t like how the Tasks plug-in formats them).

But the group headings are ISO (2025-01-16 etc.) and I would like them to read as the day of the week. So I try this:

```dataview
TASK
FLATTEN text + " 🔗 " + file.link as visual
WHERE !completed and due >= date(today) and due <= date(today) + dur(7 days)
GROUP BY dateformat(due, "EEEE")
SORT due ASC

but of course, that changes the headers to strings, which means the groups themselves are sorted alphabetically (Friday, Monday, Thursday, Tuesday, Wednesday, etc.)

Is there a way to rename the group headers to strings after the groups are sorted by their date, in a way that won’t re-sort them alphabetically? Do I need DataviewJS for this? I know a little Python, and even less Javascript. Thank you!

Would this do the trick I wonder: SORT "%%" + due + "%%" + dateformat(due, "EEEE")

It should , but you might need to b use an ISO 8601 format of due to make it correct alphanumeric.

Thank you! This worked when I added it to the GROUP BY command like below. I hadn’t thought to use commenting syntax to hide things from within the Dataview code.

```dataview
TASK
FLATTEN text + " 🔗 " + file.link as visual
WHERE !completed and due >= date(today) and due <= date(today) + dur(7 days)
GROUP BY "%%" + due + "%%" + dateformat(due, "EEEE")
SORT due

The GROUP BY do often sort stuff, so I tend to mix and match where I use this trick. I sometimes pre-sort before grouping
Glad you got it sorted.