Custom sorting on a value in Dataview

Hi im new to Obsidian. I made a Movies and Series Tracker and wanted to have Movies with the Metadata Watching on top To watch in the middel and Watched at the bottom i couldnt find anything in the docs on the sorting page. This i my Dataview Query:

table Status, ("![coverimg|95](" + Cover +")") as Cover, Rating, Metascore
from "Media/Series"

I think you could do a sort with a choice() trick.
something like:

SORT choice(Status="Watching",1,choice(Status="To watch",2,choice(Status="Watched",3,4))) ASC

A similar approach to what @cheezopath mention is to use an object to keep the sorted list, and not build that long list of choice(). Which to use is a matter of preference, as they’re mostly the same. The advantage of the choice() variant is that you are able to place the “undefined” at a given place. The object variant requires you to know all the elements of the list (unless you do some trickery with the values you use to sort on… )

The gist of the object idea is to use a SORT statement like the following:

SORT object(
  "Watching", 1,
  "To watch", 2,
  "Watched", 3
)[Status]

The way this works it to create a dictionary of the sorted positions for each of your key values, and then using [Status] to look up the position of that key value before its used to sort on.

oh that’s clean. nice!

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