Sort book's volume (property is text and I can't change it to number)

Hi!
In my Book Tracker I have a property “series” and another one as “volume”.
In the author’s note I’ve created some queries to show the books written from the author, with some block referring only to the series.
I wish the books ordered by volume but I can’t get this since 10 is put before 2 (by example)
I can’t change the property to “number” since some books are “volume 1 2” or “single volume” (with all the books referring to the series).

It would be possible to sort by volume number or I have to choose a different field for sorting? (i.e. publish date)

Thanks in advance

Could you give some examples of various sequences you’ve got, and how you’d expect them to be sorted?

This is the query:

```dataview
TABLE title as titolo, volume, stato, voto
FROM "Libri"
WHERE contains(autore, this.file.name) AND serie="Hap and Leonard"
SORT volume
The books are sorted as 1, 10, 2, 8 and not as 1, 2, 8, 10 as intended

Let me know if you need further information and thanks in advance for your help

You’re still not giving a full example of the variants in your case, like which variants of the “volume 1 2” or “volume first” do you have…

In the simple case, you could try using SORT number(volume) to try extracting the number from the text. See number().

That function will return null if there are no numbers in the text, and I’ve not test extensively how it’ll behave with multiple numbers. If you’re likely to have text only volumes, and you’ll like these to be sorted, maybe the following will work better for you: default( number(volume), volume) . That expression will pull a number out of the text, if present, or else it’ll use the text variant as is.

Thanks a lot. Your simple solution (maybe simple for you, not for me :smile: ) is the right one.
Anyway I’ll check also the link you’ve provided: I’ll learn something new and this is a good thing to do.

1 Like

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