Dataview SORT: undefined fields come first; can I make them go last?

What I’m trying to do

I manually annotate my tasks with priorities, like so:

* take out the trash [priority:: 3]

Except that not all my tasks are tagged in this way. When I try to sort all my tasks by priority, the ones with no priority are listed first (presumably because their implicit value for that property is 0?)

```dataview
TASK
SORT priority
```

Things I have tried

prioritizing and sorting in descending order (i.e., 5 is top, 1 is bottom). This works, but disagrees with my intuition.

can you do something like SORT priority+1? i wonder if that will coerce the undefined stuff?
then again that doesn’t help with your order…
maybe you could use choice() to test if there is a priority defined, and if not, add a large number, then sort by that?

TIL about choice()! Thanks a ton. For posterity, I ended up with:

```dataview
SORT BY choice(priority, priority, 99)
```

Actually, I just found out about default(), which is purpose-built for exactly this case.

```dataview
SORT BY default(priority, 99)
2 Likes

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