Dataview (no-js) sort TABLE by header

What I’m trying to do

Sort a dataview (without js) TABLE by a specified header using the AS keyword.

Things I have tried

TABLE
dateformat(event.date, "MM-dd") AS day
event.name
FROM "Contacts"
FLATTEN events AS event
WHERE event
SORT day

This doesn’t work, i.e. the table is showing, but it is not sorted (on the specified column header).
What does work is if I copy the function over to the SORT expression:

TABLE
dateformat(event.date, "MM-dd") AS day
event.name
FROM "Contacts"
FLATTEN events AS event
WHERE event
SORT dateformat(event.date, "MM-dd")

But it doesn’t use the column header like I want, and results in copies of the same expression. It’s not the end of the world, but I figured it would work similar to the use of AS in case of FLATTEN, although that is a different construct.

Using FLATTEN is the way forward, as that is kind of like a variable declaration allowing the result to be used elsewhere in the query.

So try the following:

```dataview 
TABLE day, event.name
FROM "Contacts"
FLATTEN events AS event
FLATTEN dateformat(event.date, "MM-dd") AS day
WHERE event
SORT day
```
1 Like

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