[Dataview] Sorting on a derived field for inline data possible?

What I’m trying to do

I’m keeping a bunch of dates, e.g.
1 file called Birthdays with lists where each row has [date:: mm-dd][item:: (Birthday) name], another file for example is Upcoming Reminders with lists where each row has [date:: yyyy-mm-dd][item:: (Task) Return item X by today!].

So now I want to create a dataview where it gives me upcoming items that are upcoming.

Things I have tried

So I first started with some simple query as follows

TABLE WITHOUT ID f.date_, f.item, dateformat(date(f.date_, "MM-dd"), "yyyy-MM-dd") as d
FROM #Taskable 
FLATTEN file.lists as f
WHERE f.item
SORT f.d DESC

Unfortunately this gives me a valid list but no way to sort by the derived field “d”.

I want to sort based on the derived field (so I can also change the derived field to be today - due date to order by). Is this possible?

Yes, but you need to move the calculation of the field into a FLATTEN statement (placed after any FROM clauses):

```dataview 
TABLE WITHOUT ID f.date_, f.item, d

FROM #Taskable 
FLATTEN file.lists as f
FLATTEN dateformat(date(f.date_, "MM-dd"), "yyyy-MM-dd") as d
WHERE f.item
SORT d DESC
```
1 Like

That worked perfectly, thanks~!

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