First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.
What I’m trying to do
I have written a dataview query to collect some tasks.
TASK
FROM "SecondBrain/Projects/ASTL Project"
WHERE !completed
sort choice(priority = "🔺", "1",
choice(priority= "⏫", "2",
choice(priority = "🔼", "3","4"))) asc
The query works exactly as expected in that it
it pulls tasks from the specified directory and its subdirectories
It only pulls incomplete tasks
The issue is the sort. It does nothing. The tasks are displayed, but not sorted. They look like:
- [ ] task 1
- [ ] task 2 🔼
- [ ] task 3
I expect “task 2” to be at the top of the list
Things I have tried
I originally tried just sorting on priority, but didn’t do anything. I changed to the “choice” function thinking that the sort needed the icons converted to numbers.
I looked at several posts that seemed to discuss similar issues, but none of them seemed to do what I want (or they implied that the choice should work).
I suspect that the “priority” isn’t returning what I expect. I tried “rows.priority” but that didn’t change anything.
For various reasons, I can’t use a “tasks” block for this. It has to be dataview. It seems like there should be a solution. Ideas?
If you look at Metadata on Tasks and Lists - Dataview, the last sentence in the first paragraph, you can see that priorities is not currently supported.
With that being said you should be able to use code similar to what you’ve written to accomplish your goal. You just need to replace the priority = "?" bits with contains(text, "?")
So try the following:
```dataview
TASK
FROM "SecondBrain/Projects/ASTL Project"
WHERE !completed
SORT
choice(contains(text, "🔺"), 1,
choice(contains(text, "⏫"), 2,
choice(contains(text, "🔼"), 3,
4))) asc
```
You could also consider doing stuff like the following to use the priority for grouping or filtering, and so on…
```dataview
TASK
FROM "SecondBrain/Projects/ASTL Project"
WHERE !completed
FLATTEN
choice(contains(text, "🔺"), 1,
choice(contains(text, "⏫"), 2,
choice(contains(text, "🔼"), 3,
choice(contains(text, "🔽"), 5,
choice(contains(text, "⏬️"), 6,
4))))) as priority
SORT priority
```
One could opt for using text strings here to easier read out the priority level. Do note the skip in order from 3 to 5 to allow for 4 to be normal tasks.
Both your solutions work correctly. I like the second one because it gets me a priority value. I would still like to know what priority means in my original, but that is a mystery that may remain unsolved for the time being.