Dataview: Sort by nested tag

Apologies if this has been answered elsewhere. Assume it is, but I’ve been unable to find the answer.

What I’m trying to do

I want to sort the results of a Dataview query by sub-tag. I want to use tags like #todo/1 and #todo/2 on notes and then be able to list out notes sorted by #todo.

Things I have tried

I’ve tried sorting by tag (e.g., SORT #todo) which yields an error and by tags (e.g., SORT file.etags) and index e.g., SORT file.etags[0]) neither of which works because there are often multiple tags in different sequences.

I’m sure there’s an easy way to do this but, thus far, I’ve not been able to figure it out.

Could you post your complete query?

See the entire query would indeed be helpful, but it might be that you could use filter() in combination with startswith() to achieve your goal.

Try something like:

SORT filter(file.etags, (t) => startswith(t, "#todo"))[0]

It could be you don’t need the [0] part, but try it, and see what happens. :smiley:

This should filter out only (or more precisely the first of) the tags starting with #todo and use that for your sorting.

1 Like

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